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

hub.exec.boto3.client.config.delete_retention_configuration
hub.exec.boto3.client.config.describe_retention_configurations
hub.exec.boto3.client.config.put_retention_configuration
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, retention_period_in_days: int)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates and updates the retention configuration with details about retention period (number of days) that AWS
    Config stores your historical information. The API creates the RetentionConfiguration object and names the
    object as default. When you have a RetentionConfiguration object named default, calling the API modifies the
    default object.   Currently, AWS Config supports only one retention configuration per region in your account.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        retention_period_in_days(int): Number of days AWS Config stores your historical information.  Currently, only applicable to the
            configuration item history.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.config.put_retention_configuration(
                ctx,
                
                
                **{"RetentionPeriodInDays": retention_period_in_days}
            )
            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.config.describe_retention_configurations(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, retention_configuration_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the retention configuration.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

