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

hub.exec.boto3.client.ecr_public.create_repository
hub.exec.boto3.client.ecr_public.delete_repository
hub.exec.boto3.client.ecr_public.describe_repositories
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, repository_name: Text, catalog_data: Dict = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a repository in a public registry. For more information, see Amazon ECR repositories in the Amazon
    Elastic Container Registry User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        repository_name(Text): The name to use for the repository. This appears publicly in the Amazon ECR Public Gallery. The
            repository name may be specified on its own (such as nginx-web-app) or it can be prepended with
            a namespace to group the repository into a category (such as project-a/nginx-web-app).
        catalog_data(Dict, optional): The details about the repository that are publicly visible in the Amazon ECR Public Gallery. Defaults to None.
        tags(List, optional): The metadata that you apply to the repository to help you categorize and organize them. Each tag
            consists of a key and an optional value, both of which you define. Tag keys can have a maximum
            character length of 128 characters, and tag values can have a maximum length of 256 characters. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ecr_public.create_repository(
                ctx,
                
                
                **{"repositoryName": repository_name, "catalogData": catalog_data, "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.ecr_public.describe_repositories(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, repository_name: Text, registry_id: Text = None, force: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a repository in a public registry. If the repository contains images, you must either delete all images
    in the repository or use the force option which deletes all images on your behalf before deleting the
    repository.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        registry_id(Text, optional): The AWS account ID associated with the public registry that contains the repository to delete.
            If you do not specify a registry, the default public registry is assumed. Defaults to None.
        repository_name(Text): The name of the repository to delete.
        force(bool, optional):  If a repository contains images, forces the deletion. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.ecr_public.delete_repository(
                ctx,
                
                
                **{"registryId": registry_id, "repositoryName": repository_name, "force": force}
            )
            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.ecr_public.describe_repositories(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

