import requests


def get_job_id(ome_ip_address, authenticated_headers, discovery_config_group_id) -> int:
    """
    Get job id

    Args:
        ome_ip_address: IP address of the OME server
        authenticated_headers: A dictionary of HTTP headers generated from an authenticated session with OME
        discovery_config_group_id: The group ID of all devices being discovered as part of this job

    Returns: An integer containing the job ID or -1 if the job ID could not be found
    """

    job_id = -1
    url = 'https://%s/api/DiscoveryConfigService/Jobs' % ome_ip_address
    job_resp = requests.get(url, headers=authenticated_headers, verify=False)
    if job_resp.status_code == 200:
        job_resp_object = job_resp.json()
        if job_resp_object['@odata.count'] > 0:
            for value_object in job_resp_object['value']:
                if value_object['DiscoveryConfigGroupId'] == discovery_config_group_id:
                    job_id = value_object['JobId']
                    break
        else:
            print("unable to get job id " + job_resp_object)
    else:
        print("unable to get job id.Status code:  " + str(job_resp.status_code))

    return job_id