import logging
import requests


def start(API_KEY, INPUT_SAS, CALLBACK_DESTINATION):
    """
    Creates a diagnose job on the Dolby.io server.
    Inputs:
       API_KEY: The Dolby.io media API key required for authenticating jobs.
       INPUT_SAS: The SAS URL that points to the file for diagnosis.
       CALLBACK_DESTINATION: The HTTP location the callback should point to.
    Returns: 
       Post response
    """

    logging.info("Diagnosing Azure Stored Media")
    callback_destination = CALLBACK_DESTINATION + "?job=diagnose_success" + "&input_file=" + INPUT_SAS.split("?")[0].split("/")[-1]

    #Submit a diagnose job
    url = "https://api.dolby.com/media/diagnose"
    body = {"input" : INPUT_SAS, 
    'on_complete': {'url': callback_destination, "headers": ["x-job-id"]}}
    headers = {"x-api-key":API_KEY,"Content-Type": "application/json","Accept": "application/json", "x-job-id":"True"}

    response = requests.post(url, json=body, headers=headers)
    response.raise_for_status()
    return response