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

hub.exec.boto3.client.mediastore.create_container
hub.exec.boto3.client.mediastore.delete_container
hub.exec.boto3.client.mediastore.describe_container
hub.exec.boto3.client.mediastore.list_containers
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, container_name: Text, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a storage container to hold objects. A container is similar to a bucket in the Amazon S3 service.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        container_name(Text): The name for the container. The name must be from 1 to 255 characters. Container names must be
            unique to your AWS account within a specific region. As an example, you could create a container
            named movies in every region, as long as you don’t have an existing container with that name.
        tags(List, optional): An array of key:value pairs that you define. These values can be anything that you want.
            Typically, the tag key represents a category (such as "environment") and the tag value
            represents a specific value within that category (such as "test," "development," or
            "production"). You can add up to 50 tags to each container. For more information about tagging,
            including naming and usage conventions, see Tagging Resources in MediaStore. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.mediastore.create_container(
                ctx,
                
                
                **{"ContainerName": container_name, "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.mediastore.describe_container(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 specified container. Before you make a DeleteContainer request, delete any objects in the container
    or in any folders in the container. You can delete only empty containers.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

