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

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



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, repository_name: Text, tags: List = None, image_tag_mutability: Text = None, image_scanning_configuration: Dict = None, encryption_configuration: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a repository. 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. 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).
        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.
        image_tag_mutability(Text, optional): The tag mutability setting for the repository. If this parameter is omitted, the default setting
            of MUTABLE will be used which will allow image tags to be overwritten. If IMMUTABLE is
            specified, all image tags within the repository will be immutable which will prevent them from
            being overwritten. Defaults to None.
        image_scanning_configuration(Dict, optional): The image scanning configuration for the repository. This determines whether images are scanned
            for known vulnerabilities after being pushed to the repository. Defaults to None.
        encryption_configuration(Dict, optional): The encryption configuration for the repository. This determines how the contents of your
            repository are encrypted at rest. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ecr.create_repository(
                ctx,
                
                
                **{"repositoryName": repository_name, "tags": tags, "imageTagMutability": image_tag_mutability, "imageScanningConfiguration": image_scanning_configuration, "encryptionConfiguration": encryption_configuration}
            )
            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.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. If the repository contains images, you must either delete all images in the repository or
    use the force option to delete 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 registry that contains the repository to delete. If you
            do not specify a registry, the default 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.repository.absent:
                - name: value
                - repository_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ecr.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.describe_repositories(name)

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

