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

hub.exec.boto3.client.ecs.create_capacity_provider
hub.exec.boto3.client.ecs.delete_capacity_provider
hub.exec.boto3.client.ecs.describe_capacity_providers
hub.exec.boto3.client.ecs.update_capacity_provider
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, auto_scaling_group_provider: Dict, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new capacity provider. Capacity providers are associated with an Amazon ECS cluster and are used in
    capacity provider strategies to facilitate cluster auto scaling. Only capacity providers using an Auto Scaling
    group can be created. Amazon ECS tasks on Fargate use the FARGATE and FARGATE_SPOT capacity providers which are
    already created and available to all accounts in Regions supported by Fargate.

    Args:
        name(Text): The name of the capacity provider. Up to 255 characters are allowed, including letters (upper
            and lowercase), numbers, underscores, and hyphens. The name cannot be prefixed with "aws",
            "ecs", or "fargate".
        auto_scaling_group_provider(Dict): The details of the Auto Scaling group for the capacity provider.
        tags(List, optional): The metadata that you apply to the capacity provider to help you categorize and organize them.
            Each tag consists of a key and an optional value, both of which you define. The following basic
            restrictions apply to tags:   Maximum number of tags per resource - 50   For each resource, each
            tag key must be unique, and each tag key can have only one value.   Maximum key length - 128
            Unicode characters in UTF-8   Maximum value length - 256 Unicode characters in UTF-8   If your
            tagging schema is used across multiple services and resources, remember that other services may
            have restrictions on allowed characters. Generally allowed characters are: letters, numbers, and
            spaces representable in UTF-8, and the following characters: + - = . _ : / @.   Tag keys and
            values are case-sensitive.   Do not use aws:, AWS:, or any upper or lowercase combination of
            such as a prefix for either keys or values as it is reserved for Amazon Web Services use. You
            cannot edit or delete tag keys or values with this prefix. Tags with this prefix do not count
            against your tags per resource limit. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ecs.create_capacity_provider(
                ctx,
                
                
                **{"Name": name, "autoScalingGroupProvider": auto_scaling_group_provider, "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.ecs.describe_capacity_providers(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, capacity_provider: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified capacity provider.  The FARGATE and FARGATE_SPOT capacity providers are reserved and
    cannot be deleted. You can disassociate them from a cluster using either the PutClusterCapacityProviders API or
    by deleting the cluster.  Prior to a capacity provider being deleted, the capacity provider must be removed from
    the capacity provider strategy from all services. The UpdateService API can be used to remove a capacity
    provider from a service's capacity provider strategy. When updating a service, the forceNewDeployment option can
    be used to ensure that any tasks using the Amazon EC2 instance capacity provided by the capacity provider are
    transitioned to use the capacity from the remaining capacity providers. Only capacity providers that are not
    associated with a cluster can be deleted. To remove a capacity provider from a cluster, you can either use
    PutClusterCapacityProviders or delete the cluster.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        capacity_provider(Text): The short name or full Amazon Resource Name (ARN) of the capacity provider to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

