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

hub.exec.boto3.client.ses.delete_identity_policy
hub.exec.boto3.client.ses.get_identity_policies
hub.exec.boto3.client.ses.list_identity_policies
hub.exec.boto3.client.ses.put_identity_policy
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, identity: Text, policy_name: Text, policy: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Adds or updates a sending authorization policy for the specified identity (an email address or a domain).  This
    API is for the identity owner only. If you have not verified the identity, this API will return an error.
    Sending authorization is a feature that enables an identity owner to authorize other senders to use its
    identities. For information about using sending authorization, see the Amazon SES Developer Guide. You can
    execute this operation no more than once per second.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        identity(Text): The identity that the policy will apply to. You can specify an identity by using its name or by
            using its Amazon Resource Name (ARN). Examples: user@example.com, example.com, arn:aws:ses:us-
            east-1:123456789012:identity/example.com. To successfully call this API, you must own the
            identity.
        policy_name(Text): The name of the policy. The policy name cannot exceed 64 characters and can only include
            alphanumeric characters, dashes, and underscores.
        policy(Text): The text of the policy in JSON format. The policy cannot exceed 4 KB. For information about the
            syntax of sending authorization policies, see the Amazon SES Developer Guide.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.ses.identity_policy.present:
                - name: value
                - identity: value
                - policy_name: value
                - policy: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ses.identity_policy.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.ses.get_identity_policies(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ses.put_identity_policy(
                ctx,
                
                
                **{"Identity": identity, "PolicyName": policy_name, "Policy": policy}
            )
            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.ses.get_identity_policies(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, identity: Text, policy_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified sending authorization policy for the given identity (an email address or a domain). This
    API returns successfully even if a policy with the specified name does not exist.  This API is for the identity
    owner only. If you have not verified the identity, this API will return an error.  Sending authorization is a
    feature that enables an identity owner to authorize other senders to use its identities. For information about
    using sending authorization, see the Amazon SES Developer Guide. You can execute this operation no more than
    once per second.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        identity(Text): The identity that is associated with the policy that you want to delete. You can specify the
            identity by using its name or by using its Amazon Resource Name (ARN). Examples:
            user@example.com, example.com, arn:aws:ses:us-east-1:123456789012:identity/example.com. To
            successfully call this API, you must own the identity.
        policy_name(Text): The name of the policy to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.ses.identity_policy.absent:
                - name: value
                - identity: value
                - policy_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ses.identity_policy.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.ses.get_identity_policies(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.ses.delete_identity_policy(
                ctx,
                
                
                **{"Identity": identity, "PolicyName": policy_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.ses.get_identity_policies(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

