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

hub.exec.boto3.client.dlm.create_lifecycle_policy
hub.exec.boto3.client.dlm.delete_lifecycle_policy
hub.exec.boto3.client.dlm.get_lifecycle_policy
hub.exec.boto3.client.dlm.update_lifecycle_policy
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, execution_role_arn: Text, description: Text, state: Text, policy_details: Dict, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a policy to manage the lifecycle of the specified AWS resources. You can create up to 100 lifecycle
    policies.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        execution_role_arn(Text): The Amazon Resource Name (ARN) of the IAM role used to run the operations specified by the
            lifecycle policy.
        description(Text): A description of the lifecycle policy. The characters ^[0-9A-Za-z _-]+$ are supported.
        state(Text): The desired activation state of the lifecycle policy after creation.
        policy_details(Dict): The configuration details of the lifecycle policy.
        tags(Dict, optional): The tags to apply to the lifecycle policy during creation. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.dlm.lifecycle_policy.present:
                - name: value
                - execution_role_arn: value
                - description: value
                - state: value
                - policy_details: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.dlm.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.dlm.get_lifecycle_policy(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.dlm.create_lifecycle_policy(
                ctx,
                
                
                **{"ExecutionRoleArn": execution_role_arn, "Description": description, "State": state, "PolicyDetails": policy_details, "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.dlm.get_lifecycle_policy(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, policy_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified lifecycle policy and halts the automated operations that the policy specified.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        policy_id(Text): The identifier of the lifecycle policy.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

