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

hub.exec.boto3.client.appconfig.create_deployment_strategy
hub.exec.boto3.client.appconfig.delete_deployment_strategy
hub.exec.boto3.client.appconfig.get_deployment_strategy
hub.exec.boto3.client.appconfig.list_deployment_strategies
hub.exec.boto3.client.appconfig.update_deployment_strategy
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, deployment_duration_in_minutes: int, growth_factor: float, replicate_to: Text, description: Text = None, final_bake_time_in_minutes: int = None, growth_type: Text = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    A deployment strategy defines important criteria for rolling out your configuration to the designated targets. A
    deployment strategy includes: the overall duration required, a percentage of targets to receive the deployment
    during each interval, an algorithm that defines how percentage grows, and bake time.

    Args:
        name(Text): A name for the deployment strategy.
        description(Text, optional): A description of the deployment strategy. Defaults to None.
        deployment_duration_in_minutes(int): Total amount of time for a deployment to last.
        final_bake_time_in_minutes(int, optional): The amount of time AppConfig monitors for alarms before considering the deployment to be
            complete and no longer eligible for automatic roll back. Defaults to None.
        growth_factor(float): The percentage of targets to receive a deployed configuration during each interval.
        growth_type(Text, optional): The algorithm used to define how percentage grows over time. AWS AppConfig supports the
            following growth types:  Linear: For this type, AppConfig processes the deployment by dividing
            the total number of targets by the value specified for Step percentage. For example, a linear
            deployment that uses a Step percentage of 10 deploys the configuration to 10 percent of the
            hosts. After those deployments are complete, the system deploys the configuration to the next 10
            percent. This continues until 100% of the targets have successfully received the configuration.
            Exponential: For this type, AppConfig processes the deployment exponentially using the following
            formula: G*(2^N). In this formula, G is the growth factor specified by the user and N is the
            number of steps until the configuration is deployed to all targets. For example, if you specify
            a growth factor of 2, then the system rolls out the configuration as follows:  2*(2^0)   2*(2^1)
            2*(2^2)  Expressed numerically, the deployment rolls out as follows: 2% of the targets, 4% of
            the targets, 8% of the targets, and continues until the configuration has been deployed to all
            targets. Defaults to None.
        replicate_to(Text): Save the deployment strategy to a Systems Manager (SSM) document.
        tags(Dict, optional): Metadata to assign to the deployment strategy. Tags help organize and categorize your AppConfig
            resources. Each tag consists of a key and an optional value, both of which you define. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.appconfig.deployment_strategy.present:
                - name: value
                - deployment_duration_in_minutes: value
                - growth_factor: value
                - replicate_to: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.appconfig.deployment_strategy.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.appconfig.get_deployment_strategy(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.appconfig.create_deployment_strategy(
                ctx,
                
                
                **{"Name": name, "Description": description, "DeploymentDurationInMinutes": deployment_duration_in_minutes, "FinalBakeTimeInMinutes": final_bake_time_in_minutes, "GrowthFactor": growth_factor, "GrowthType": growth_type, "ReplicateTo": replicate_to, "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.appconfig.get_deployment_strategy(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, deployment_strategy_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Delete a deployment strategy. Deleting a deployment strategy does not delete a configuration from a host.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        deployment_strategy_id(Text): The ID of the deployment strategy you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

