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

hub.exec.boto3.client.codeartifact.delete_domain_permissions_policy
hub.exec.boto3.client.codeartifact.get_domain_permissions_policy
hub.exec.boto3.client.codeartifact.put_domain_permissions_policy
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, domain: Text, policy_document: Text, domain_owner: Text = None, policy_revision: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Sets a resource policy on a domain that specifies permissions to access it.   When you call
    PutDomainPermissionsPolicy, the resource policy on the domain is ignored when evaluting permissions. This
    ensures that the owner of a domain cannot lock themselves out of the domain, which would prevent them from being
    able to update the resource policy.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        domain(Text):  The name of the domain on which to set the resource policy.
        domain_owner(Text, optional):  The 12-digit account number of the AWS account that owns the domain. It does not include dashes
            or spaces. Defaults to None.
        policy_revision(Text, optional):  The current revision of the resource policy to be set. This revision is used for optimistic
            locking, which prevents others from overwriting your changes to the domain's resource policy. Defaults to None.
        policy_document(Text):  A valid displayable JSON Aspen policy string to be set as the access control resource policy on
            the provided domain.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.codeartifact.domain_permissions_policy.present:
                - name: value
                - domain: value
                - policy_document: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.codeartifact.domain_permissions_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.codeartifact.get_domain_permissions_policy(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.codeartifact.put_domain_permissions_policy(
                ctx,
                
                
                **{"domain": domain, "domainOwner": domain_owner, "policyRevision": policy_revision, "policyDocument": policy_document}
            )
            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.codeartifact.get_domain_permissions_policy(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, domain: Text, domain_owner: Text = None, policy_revision: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Deletes the resource policy set on a domain.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        domain(Text):  The name of the domain associated with the resource policy to be deleted.
        domain_owner(Text, optional):  The 12-digit account number of the AWS account that owns the domain. It does not include dashes
            or spaces. Defaults to None.
        policy_revision(Text, optional):  The current revision of the resource policy to be deleted. This revision is used for optimistic
            locking, which prevents others from overwriting your changes to the domain's resource policy. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.codeartifact.domain_permissions_policy.absent:
                - name: value
                - domain: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.codeartifact.domain_permissions_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.codeartifact.get_domain_permissions_policy(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.codeartifact.delete_domain_permissions_policy(
                ctx,
                
                
                **{"domain": domain, "domainOwner": domain_owner, "policyRevision": policy_revision}
            )
            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.codeartifact.get_domain_permissions_policy(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

