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

hub.exec.boto3.client.sagemaker.create_code_repository
hub.exec.boto3.client.sagemaker.delete_code_repository
hub.exec.boto3.client.sagemaker.describe_code_repository
hub.exec.boto3.client.sagemaker.list_code_repositories
hub.exec.boto3.client.sagemaker.update_code_repository
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, code_repository_name: Text, git_config: Dict, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a Git repository as a resource in your Amazon SageMaker account. You can associate the repository with
    notebook instances so that you can use Git source control for the notebooks you create. The Git repository is a
    resource in your Amazon SageMaker account, so it can be associated with more than one notebook instance, and it
    persists independently from the lifecycle of any notebook instances it is associated with. The repository can be
    hosted either in Amazon Web Services CodeCommit or in any other Git repository.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        code_repository_name(Text): The name of the Git repository. The name must have 1 to 63 characters. Valid characters are a-z,
            A-Z, 0-9, and - (hyphen).
        git_config(Dict): Specifies details about the repository, including the URL where the repository is located, the
            default branch, and credentials to use to access the repository.
        tags(List, optional): An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources
            in different ways, for example, by purpose, owner, or environment. For more information, see
            Tagging Amazon Web Services Resources. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.sagemaker.code_repository.present:
                - name: value
                - code_repository_name: value
                - git_config: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.sagemaker.code_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.sagemaker.describe_code_repository(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.sagemaker.create_code_repository(
                ctx,
                
                
                **{"CodeRepositoryName": code_repository_name, "GitConfig": git_config, "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.sagemaker.describe_code_repository(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, code_repository_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified Git repository from your account.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

