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

hub.exec.boto3.client.ecr.delete_registry_policy
hub.exec.boto3.client.ecr.get_registry_policy
hub.exec.boto3.client.ecr.put_registry_policy
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, policy_text: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates or updates the permissions policy for your registry. A registry policy is used to specify permissions
    for another AWS account and is used when configuring cross-account replication. For more information, see
    Registry permissions in the Amazon Elastic Container Registry User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        policy_text(Text): The JSON policy text to apply to your registry. The policy text follows the same format as IAM
            policy text. For more information, see Registry permissions in the Amazon Elastic Container
            Registry User Guide.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the registry permissions policy.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

