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

hub.exec.boto3.client.ecs.delete_attributes
hub.exec.boto3.client.ecs.list_attributes
hub.exec.boto3.client.ecs.put_attributes
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, attributes: List, cluster: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Create or update an attribute on an Amazon ECS resource. If the attribute does not exist, it is created. If the
    attribute exists, its value is replaced with the specified value. To delete an attribute, use DeleteAttributes.
    For more information, see Attributes in the Amazon Elastic Container Service Developer Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        cluster(Text, optional): The short name or full Amazon Resource Name (ARN) of the cluster that contains the resource to
            apply attributes. If you do not specify a cluster, the default cluster is assumed. Defaults to None.
        attributes(List): The attributes to apply to your resource. You can specify up to 10 custom attributes per
            resource. You can specify up to 10 attributes in a single call.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, attributes: List, cluster: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes one or more custom attributes from an Amazon ECS resource.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        cluster(Text, optional): The short name or full Amazon Resource Name (ARN) of the cluster that contains the resource to
            delete attributes. If you do not specify a cluster, the default cluster is assumed. Defaults to None.
        attributes(List): The attributes to delete from your resource. You can specify up to 10 attributes per request.
            For custom attributes, specify the attribute name and target ID, but do not specify the value.
            If you specify the target ID using the short form, you must also specify the target type.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

