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

hub.exec.boto3.client.iot.create_authorizer
hub.exec.boto3.client.iot.delete_authorizer
hub.exec.boto3.client.iot.describe_authorizer
hub.exec.boto3.client.iot.list_authorizers
hub.exec.boto3.client.iot.update_authorizer
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, authorizer_name: Text, authorizer_function_arn: Text, token_key_name: Text = None, token_signing_public_keys: Dict = None, status: Text = None, tags: List = None, signing_disabled: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an authorizer.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        authorizer_name(Text): The authorizer name.
        authorizer_function_arn(Text): The ARN of the authorizer's Lambda function.
        token_key_name(Text, optional): The name of the token key used to extract the token from the HTTP headers. Defaults to None.
        token_signing_public_keys(Dict, optional): The public keys used to verify the digital signature returned by your custom authentication
            service. Defaults to None.
        status(Text, optional): The status of the create authorizer request. Defaults to None.
        tags(List, optional): Metadata which can be used to manage the custom authorizer.  For URI Request parameters use
            format: ...key1=value1&key2=value2... For the CLI command-line parameter use format: &&tags
            "key1=value1&key2=value2..." For the cli-input-json file use format: "tags":
            "key1=value1&key2=value2...". Defaults to None.
        signing_disabled(bool, optional): Specifies whether AWS IoT validates the token signature in an authorization request. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.iot.authorizer.present:
                - name: value
                - authorizer_name: value
                - authorizer_function_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iot.authorizer.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.iot.describe_authorizer(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iot.create_authorizer(
                ctx,
                
                
                **{"authorizerName": authorizer_name, "authorizerFunctionArn": authorizer_function_arn, "tokenKeyName": token_key_name, "tokenSigningPublicKeys": token_signing_public_keys, "status": status, "tags": tags, "signingDisabled": signing_disabled}
            )
            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.iot.describe_authorizer(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, authorizer_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an authorizer.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        authorizer_name(Text): The name of the authorizer to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.iot.authorizer.absent:
                - name: value
                - authorizer_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iot.authorizer.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.iot.describe_authorizer(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.iot.delete_authorizer(
                ctx,
                
                
                **{"authorizerName": authorizer_name}
            )
            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.iot.describe_authorizer(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

