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

hub.exec.boto3.client.mediastore.delete_lifecycle_policy
hub.exec.boto3.client.mediastore.get_lifecycle_policy
hub.exec.boto3.client.mediastore.put_lifecycle_policy
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, container_name: Text, lifecycle_policy: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Writes an object lifecycle policy to a container. If the container already has an object lifecycle policy, the
    service replaces the existing policy with the new policy. It takes up to 20 minutes for the change to take
    effect. For information about how to construct an object lifecycle policy, see Components of an Object Lifecycle
    Policy.

    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 object lifecycle policy to.
        lifecycle_policy(Text): The object lifecycle policy to apply to the container.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.mediastore.put_lifecycle_policy(
                ctx,
                
                
                **{"ContainerName": container_name, "LifecyclePolicy": lifecycle_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_lifecycle_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**
    
    Removes an object lifecycle policy from a container. It takes up to 20 minutes for the change 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 holds the object lifecycle policy.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

