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

hub.exec.boto3.client.codeartifact.create_repository
hub.exec.boto3.client.codeartifact.delete_repository
hub.exec.boto3.client.codeartifact.describe_repository
hub.exec.boto3.client.codeartifact.list_repositories
hub.exec.boto3.client.codeartifact.update_repository
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, domain: Text, repository: Text, domain_owner: Text = None, description: Text = None, upstreams: List = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Creates a repository.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        domain(Text):  The name of the domain that contains the created repository.
        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.
        repository(Text):  The name of the repository to create.
        description(Text, optional):  A description of the created repository. Defaults to None.
        upstreams(List, optional):  A list of upstream repositories to associate with the repository. The order of the upstream
            repositories in the list determines their priority order when AWS CodeArtifact looks for a
            requested package version. For more information, see Working with upstream repositories. Defaults to None.
        tags(List, optional): One or more tag key-value pairs for the repository. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

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

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

