module IDRAC::Lifecycle

def get_lifecycle_status_modern_firmware

Check if the Lifecycle Controller is enabled
def get_lifecycle_status_modern_firmware
  # Try the standard Attributes endpoint first
  path = "/redfish/v1/Managers/iDRAC.Embedded.1/Attributes"
  response = authenticated_request(:get, path)
  
  if response.status == 200
    begin
      attributes_data = JSON.parse(response.body)
      if attributes_data["Attributes"] && attributes_data["Attributes"]["LCAttributes.1.LifecycleControllerState"]
        lifecycle_state = attributes_data["Attributes"]["LCAttributes.1.LifecycleControllerState"]
        debug "Lifecycle Controller state (from Attributes): #{lifecycle_state}".light_cyan, 1
        return lifecycle_state == "Enabled"
      end
    rescue JSON::ParserError
      debug "Failed to parse Attributes response".yellow, 1
      # Fall through to registry method if parsing fails or attribute not found
    end
  else
    debug "Failed to get Attributes endpoint (Status: #{response.status}), trying registry method...".yellow, 1
  end
  
  # Try getting the DellAttributes for LifecycleController directly
  # The key insight is that we need to use just the base path without the fragment
  attributes_path = "/redfish/v1/Managers/iDRAC.Embedded.1/Oem/Dell/DellAttributes/LifecycleController.Embedded.1"
  attributes_response = authenticated_request(:get, attributes_path)
  
  if attributes_response.status == 200
    begin
      dell_attr_data = JSON.parse(attributes_response.body)
      if dell_attr_data["Attributes"] && dell_attr_data["Attributes"]["LCAttributes.1.LifecycleControllerState"]
        lifecycle_state = dell_attr_data["Attributes"]["LCAttributes.1.LifecycleControllerState"]
        debug "Lifecycle Controller state (from Dell Attributes): #{lifecycle_state}".light_cyan, 1
        return lifecycle_state == "Enabled"
      end
    rescue JSON::ParserError
      debug "Failed to parse Dell Attributes response".yellow, 1
      # Fall through to registry method if parsing fails or attribute not found
    end
  else
    debug "Failed to get Dell Attributes (Status: #{attributes_response.status}), trying registry method...".yellow, 1
  end
  
  # Fallback to the registry method if both Attributes endpoints fail
  registry_response = authenticated_request(
    :get,
    "/redfish/v1/Registries/ManagerAttributeRegistry/ManagerAttributeRegistry.v1_0_0.json"
  )
  
  if registry_response.status != 200                                                                                               
    debug "Failed to get Lifecycle Controller Attributes Registry", 0, :red                                                             
    return false                                                                                                         
  end
  
  begin
    registry_data = JSON.parse(registry_response.body)
    # This is the attribute we want:                                                                                       
    target = registry_data['RegistryEntries']['Attributes'].find {|q| q['AttributeName'] =~ /LCAttributes.1.LifecycleControllerState/ }
    if !target
      debug "Could not find LCAttributes.1.LifecycleControllerState in registry", 0, :red
      return false
    end
    
    debug "Found attribute in registry but couldn't access it via other endpoints".yellow, 1
    return false
  rescue JSON::ParserError, NoMethodError, StandardError => e
    debug "Error during registry access: #{e.message}", 0, :red
    return false
  end
end