"""
Autogenerated state module using `pop-create-idem <https://gitlab.com/saltstack/pop/pop-create-idem>`__

hub.exec.boto3.client.mturk.create_qualification_type
hub.exec.boto3.client.mturk.delete_qualification_type
hub.exec.boto3.client.mturk.get_qualification_type
hub.exec.boto3.client.mturk.list_qualification_types
hub.exec.boto3.client.mturk.update_qualification_type
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, description: Text, qualification_type_status: Text, keywords: Text = None, retry_delay_in_seconds: int = None, test: Text = None, answer_key: Text = None, test_duration_in_seconds: int = None, auto_granted: bool = None, auto_granted_value: int = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     The CreateQualificationType operation creates a new Qualification type, which is represented by a
    QualificationType data structure.

    Args:
        name(Text):  The name you give to the Qualification type. The type name is used to represent the
            Qualification to Workers, and to find the type using a Qualification type search. It must be
            unique across all of your Qualification types.
        keywords(Text, optional): One or more words or phrases that describe the Qualification type, separated by commas. The
            keywords of a type make the type easier to find during a search. Defaults to None.
        description(Text): A long description for the Qualification type. On the Amazon Mechanical Turk website, the long
            description is displayed when a Worker examines a Qualification type.
        qualification_type_status(Text): The initial status of the Qualification type. Constraints: Valid values are: Active | Inactive.
        retry_delay_in_seconds(int, optional): The number of seconds that a Worker must wait after requesting a Qualification of the
            Qualification type before the worker can retry the Qualification request. Constraints: None. If
            not specified, retries are disabled and Workers can request a Qualification of this type only
            once, even if the Worker has not been granted the Qualification. It is not possible to disable
            retries for a Qualification type after it has been created with retries enabled. If you want to
            disable retries, you must delete existing retry-enabled Qualification type and then create a new
            Qualification type with retries disabled. Defaults to None.
        test(Text, optional):  The questions for the Qualification test a Worker must answer correctly to obtain a
            Qualification of this type. If this parameter is specified, TestDurationInSeconds must also be
            specified.  Constraints: Must not be longer than 65535 bytes. Must be a QuestionForm data
            structure. This parameter cannot be specified if AutoGranted is true. Constraints: None. If not
            specified, the Worker may request the Qualification without answering any questions. Defaults to None.
        answer_key(Text, optional): The answers to the Qualification test specified in the Test parameter, in the form of an
            AnswerKey data structure. Constraints: Must not be longer than 65535 bytes. Constraints: None.
            If not specified, you must process Qualification requests manually. Defaults to None.
        test_duration_in_seconds(int, optional): The number of seconds the Worker has to complete the Qualification test, starting from the time
            the Worker requests the Qualification. Defaults to None.
        auto_granted(bool, optional): Specifies whether requests for the Qualification type are granted immediately, without prompting
            the Worker with a Qualification test. Constraints: If the Test parameter is specified, this
            parameter cannot be true. Defaults to None.
        auto_granted_value(int, optional): The Qualification value to use for automatically granted Qualifications. This parameter is used
            only if the AutoGranted parameter is true. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.mturk.qualification_type.present:
                - name: value
                - description: value
                - qualification_type_status: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.mturk.qualification_type.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    
    before = await hub.exec.boto3.client.mturk.get_qualification_type(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.mturk.create_qualification_type(
                ctx,
                
                
                **{"Name": name, "Keywords": keywords, "Description": description, "QualificationTypeStatus": qualification_type_status, "RetryDelayInSeconds": retry_delay_in_seconds, "Test": test, "AnswerKey": answer_key, "TestDurationInSeconds": test_duration_in_seconds, "AutoGranted": auto_granted, "AutoGrantedValue": auto_granted_value}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            ret["comment"] = f"Created '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    
    # TODO perform other modifications as needed here
    ...

    after = await hub.exec.boto3.client.mturk.get_qualification_type(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, qualification_type_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     The DeleteQualificationType deletes a Qualification type and deletes any HIT types that are associated with the
    Qualification type.  This operation does not revoke Qualifications already assigned to Workers because the
    Qualifications might be needed for active HITs. If there are any pending requests for the Qualification type,
    Amazon Mechanical Turk rejects those requests. After you delete a Qualification type, you can no longer use it
    to create HITs or HIT types.  DeleteQualificationType must wait for all the HITs that use the deleted
    Qualification type to be deleted before completing. It may take up to 48 hours before DeleteQualificationType
    completes and the unique name of the Qualification type is available for reuse with CreateQualificationType.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        qualification_type_id(Text): The ID of the QualificationType to dispose.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.mturk.qualification_type.absent:
                - name: value
                - qualification_type_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.mturk.qualification_type.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    

    before = await hub.exec.boto3.client.mturk.get_qualification_type(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.mturk.delete_qualification_type(
                ctx,
                
                
                **{"QualificationTypeId": qualification_type_id}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            result["comment"] = f"Deleted '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    

    after = await hub.exec.boto3.client.mturk.get_qualification_type(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

