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

hub.exec.boto3.client.mediastore.delete_metric_policy
hub.exec.boto3.client.mediastore.get_metric_policy
hub.exec.boto3.client.mediastore.put_metric_policy
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, container_name: Text, metric_policy: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    The metric policy that you want to add to the container. A metric policy allows AWS Elemental MediaStore to send
    metrics to Amazon CloudWatch. It takes up to 20 minutes for the new policy to take effect.

    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 add the metric policy to.
        metric_policy(Dict): The metric policy that you want to associate with the container. In the policy, you must
            indicate whether you want MediaStore to send container-level metrics. You can also include up to
            five rules to define groups of objects that you want MediaStore to send object-level metrics
            for. If you include rules in the policy, construct each rule with both of the following:   An
            object group that defines which objects to include in the group. The definition can be a path or
            a file name, but it can't have more than 900 characters. Valid characters are: a-z, A-Z, 0-9, _
            (underscore), = (equal), : (colon), . (period), - (hyphen), ~ (tilde), / (forward slash), and *
            (asterisk). Wildcards (*) are acceptable.   An object group name that allows you to refer to the
            object group. The name can't have more than 30 characters. Valid characters are: a-z, A-Z, 0-9,
            and _ (underscore).

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.mediastore.put_metric_policy(
                ctx,
                
                
                **{"ContainerName": container_name, "MetricPolicy": metric_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_metric_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 metric policy that is associated with the specified container. If there is no metric policy
    associated with the container, MediaStore doesn't send metrics to CloudWatch.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        container_name(Text): The name of the container that is associated with the metric policy that you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

