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

hub.exec.boto3.client.mediastore.delete_cors_policy
hub.exec.boto3.client.mediastore.get_cors_policy
hub.exec.boto3.client.mediastore.put_cors_policy
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, container_name: Text, cors_policy: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Sets the cross-origin resource sharing (CORS) configuration on a container so that the container can service
    cross-origin requests. For example, you might want to enable a request whose origin is http://www.example.com to
    access your AWS Elemental MediaStore container at my.example.container.com by using the browser's XMLHttpRequest
    capability. To enable CORS on a container, you attach a CORS policy to the container. In the CORS policy, you
    configure rules that identify origins and the HTTP methods that can be executed on your container. The policy
    can contain up to 398,000 characters. You can add up to 100 rules to a CORS policy. If more than one rule
    applies, the service uses the first applicable rule listed. To learn more about CORS, see Cross-Origin Resource
    Sharing (CORS) in AWS Elemental MediaStore.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        container_name(Text): The name of the container that you want to assign the CORS policy to.
        cors_policy(List): The CORS policy to apply to the container.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.mediastore.put_cors_policy(
                ctx,
                
                
                **{"ContainerName": container_name, "CorsPolicy": cors_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_cors_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 cross-origin resource sharing (CORS) configuration information that is set for the container. To use
    this operation, you must have permission to perform the MediaStore:DeleteCorsPolicy action. The container owner
    has this permission by default and can grant this permission to others.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

