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

hub.exec.boto3.client.mediastore.delete_container_policy
hub.exec.boto3.client.mediastore.get_container_policy
hub.exec.boto3.client.mediastore.put_container_policy
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, container_name: Text, policy: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an access policy for the specified container to restrict the users and clients that can access it. For
    information about the data that is included in an access policy, see the AWS Identity and Access Management User
    Guide. For this release of the REST API, you can create only one policy for a container. If you enter
    PutContainerPolicy twice, the second command modifies the existing policy.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        container_name(Text): The name of the container.
        policy(Text): The contents of the policy, which includes the following:    One Version tag   One Statement tag
            that contains the standard tags for the policy.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.mediastore.container_policy.present:
                - name: value
                - container_name: value
                - policy: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.mediastore.container_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.mediastore.get_container_policy(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.mediastore.put_container_policy(
                ctx,
                
                
                **{"ContainerName": container_name, "Policy": policy}
            )
            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.mediastore.get_container_policy(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, container_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the access policy that is associated with the specified container.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        container_name(Text): The name of the container that holds the policy.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

