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

hub.exec.boto3.client.codedeploy.create_deployment_config
hub.exec.boto3.client.codedeploy.delete_deployment_config
hub.exec.boto3.client.codedeploy.get_deployment_config
hub.exec.boto3.client.codedeploy.list_deployment_configs
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, deployment_config_name: Text, minimum_healthy_hosts: Dict = None, traffic_routing_config: Dict = None, compute_platform: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Creates a deployment configuration.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        deployment_config_name(Text): The name of the deployment configuration to create.
        minimum_healthy_hosts(Dict, optional): The minimum number of healthy instances that should be available at any time during the
            deployment. There are two parameters expected in the input: type and value. The type parameter
            takes either of the following values:   HOST_COUNT: The value parameter represents the minimum
            number of healthy instances as an absolute value.   FLEET_PERCENT: The value parameter
            represents the minimum number of healthy instances as a percentage of the total number of
            instances in the deployment. If you specify FLEET_PERCENT, at the start of the deployment, AWS
            CodeDeploy converts the percentage to the equivalent number of instances and rounds up
            fractional instances.   The value parameter takes an integer. For example, to set a minimum of
            95% healthy instance, specify a type of FLEET_PERCENT and a value of 95. Defaults to None.
        traffic_routing_config(Dict, optional): The configuration that specifies how the deployment traffic is routed. Defaults to None.
        compute_platform(Text, optional): The destination platform type for the deployment (Lambda, Server, or ECS). Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.codedeploy.create_deployment_config(
                ctx,
                
                
                **{"deploymentConfigName": deployment_config_name, "minimumHealthyHosts": minimum_healthy_hosts, "trafficRoutingConfig": traffic_routing_config, "computePlatform": compute_platform}
            )
            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.codedeploy.get_deployment_config(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, deployment_config_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a deployment configuration.  A deployment configuration cannot be deleted if it is currently in use.
    Predefined configurations cannot be deleted.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        deployment_config_name(Text): The name of a deployment configuration associated with the IAM user or AWS account.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

