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

hub.exec.boto3.client.codeartifact.create_domain
hub.exec.boto3.client.codeartifact.delete_domain
hub.exec.boto3.client.codeartifact.describe_domain
hub.exec.boto3.client.codeartifact.list_domains
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, domain: Text, encryption_key: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Creates a domain. CodeArtifact domains make it easier to manage multiple repositories across an organization.
    You can use a domain to apply permissions across many repositories owned by different AWS accounts. An asset is
    stored only once in a domain, even if it's in multiple repositories.  Although you can have multiple domains, we
    recommend a single production domain that contains all published artifacts so that your development teams can
    find and share packages. You can use a second pre-production domain to test changes to the production domain
    configuration.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        domain(Text):  The name of the domain to create. All domain names in an AWS Region that are in the same AWS
            account must be unique. The domain name is used as the prefix in DNS hostnames. Do not use
            sensitive information in a domain name because it is publicly discoverable.
        encryption_key(Text, optional):  The encryption key for the domain. This is used to encrypt content stored in a domain. An
            encryption key can be a key ID, a key Amazon Resource Name (ARN), a key alias, or a key alias
            ARN. To specify an encryptionKey, your IAM role must have kms:DescribeKey and kms:CreateGrant
            permissions on the encryption key that is used. For more information, see DescribeKey in the AWS
            Key Management Service API Reference and AWS KMS API Permissions Reference in the AWS Key
            Management Service Developer Guide.    CodeArtifact supports only symmetric CMKs. Do not
            associate an asymmetric CMK with your domain. For more information, see Using symmetric and
            asymmetric keys in the AWS Key Management Service Developer Guide. Defaults to None.
        tags(List, optional): One or more tag key-value pairs for the domain. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.codeartifact.create_domain(
                ctx,
                
                
                **{"domain": domain, "encryptionKey": encryption_key, "tags": tags}
            )
            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.describe_domain(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, domain: Text, domain_owner: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Deletes a domain. You cannot delete a domain that contains repositories. If you want to delete a domain with
    repositories, first delete its repositories.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        domain(Text):  The name of the domain to delete.
        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.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

