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

hub.exec.boto3.client.codecommit.create_repository
hub.exec.boto3.client.codecommit.delete_repository
hub.exec.boto3.client.codecommit.get_repository
hub.exec.boto3.client.codecommit.list_repositories
"""



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

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        repository_name(Text): The name of the new repository to be created.  The repository name must be unique across the
            calling AWS account. Repository names are limited to 100 alphanumeric, dash, and underscore
            characters, and cannot include certain characters. For more information about the limits on
            repository names, see Limits in the AWS CodeCommit User Guide. The suffix .git is prohibited.
        repository_description(Text, optional): A comment or description about the new repository.  The description field for a repository
            accepts all HTML characters and all valid Unicode characters. Applications that do not HTML-
            encode the description and display it in a webpage can expose users to potentially malicious
            code. Make sure that you HTML-encode the description field in any application that uses this API
            to display the repository description on a webpage. Defaults to None.
        tags(Dict, optional): One or more tag key-value pairs to use when tagging this repository. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, repository_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a repository. If a specified repository was already deleted, a null repository ID is returned.  Deleting
    a repository also deletes all associated objects and metadata. After a repository is deleted, all future push
    calls to the deleted repository fail.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        repository_name(Text): The name of the repository to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

