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

hub.exec.boto3.client.discovery.create_tags
hub.exec.boto3.client.discovery.delete_tags
hub.exec.boto3.client.discovery.describe_tags
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, configuration_ids: List, tags: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates one or more tags for configuration items. Tags are metadata that help you categorize IT assets. This API
    accepts a list of multiple configuration items.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        configuration_ids(List): A list of configuration items that you want to tag.
        tags(List): Tags that you want to associate with one or more configuration items. Specify the tags that you
            want to create in a key-value format. For example:  {"key": "serverType", "value": "webServer"}.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.discovery.tag.present:
                - name: value
                - configuration_ids: value
                - tags: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.discovery.tag.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.discovery.describe_tags(name)

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

async def absent(hub, ctx, name: Text, configuration_ids: List, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the association between configuration items and one or more tags. This API accepts a list of multiple
    configuration items.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        configuration_ids(List): A list of configuration items with tags that you want to delete.
        tags(List, optional): Tags that you want to delete from one or more configuration items. Specify the tags that you
            want to delete in a key-value format. For example:  {"key": "serverType", "value": "webServer"}. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

