module IDRAC::Jobs

def force_clear_jobs!

Force clear the job queue
def force_clear_jobs!
  # Clear the job queue using force option which will also clear any pending data and restart processes
  path = '/redfish/v1/Dell/Managers/iDRAC.Embedded.1/DellJobService/Actions/DellJobService.DeleteJobQueue'
  payload = { "JobID" => "JID_CLEARALL_FORCE" }
  
  response = authenticated_request(
    :post, 
    path, 
    body: payload.to_json, 
    headers: { 'Content-Type' => 'application/json' }
  )
  
  if response.status.between?(200, 299)
    puts "Successfully force-cleared job queue".green
    
    # Monitor LC status until it's Ready
    puts "Waiting for LC status to be Ready..."
    
    retries = 12  # ~2 minutes with 10s sleep
    while retries > 0
      lc_response = authenticated_request(
        :post, 
        '/redfish/v1/Dell/Managers/iDRAC.Embedded.1/DellLCService/Actions/DellLCService.GetRemoteServicesAPIStatus',
        body: {}.to_json, 
        headers: { 'Content-Type': 'application/json' }
      )
      
      if lc_response.status.between?(200, 299)
        begin
          lc_data = JSON.parse(lc_response.body)
          status = lc_data["LCStatus"]
          
          if status == "Ready"
            puts "LC Status is Ready".green
            return true
          end
          
          puts "Current LC Status: #{status}. Waiting..."
        rescue JSON::ParserError
          puts "Failed to parse LC status response, will retry...".yellow
        end
      end
      
      retries -= 1
      sleep 10
    end
    
    puts "Warning: LC status did not reach Ready state within timeout".yellow
    return true
  else
    error_message = "Failed to force-clear job queue. Status code: #{response.status}"
    
    begin
      error_data = JSON.parse(response.body)
      error_message += ", Message: #{error_data['error']['message']}" if error_data['error'] && error_data['error']['message']
    rescue
      # Ignore JSON parsing errors
    end
    
    raise Error, error_message
  end
end