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

hub.exec.boto3.client.iot.create_thing_type
hub.exec.boto3.client.iot.delete_thing_type
hub.exec.boto3.client.iot.deprecate_thing_type
hub.exec.boto3.client.iot.describe_thing_type
hub.exec.boto3.client.iot.list_thing_types
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, thing_type_name: Text, thing_type_properties: Dict = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new thing type.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        thing_type_name(Text): The name of the thing type.
        thing_type_properties(Dict, optional): The ThingTypeProperties for the thing type to create. It contains information about the new
            thing type including a description, and a list of searchable thing attribute names. Defaults to None.
        tags(List, optional): Metadata which can be used to manage the thing type. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iot.create_thing_type(
                ctx,
                
                
                **{"thingTypeName": thing_type_name, "thingTypeProperties": thing_type_properties, "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.iot.describe_thing_type(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, thing_type_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified thing type. You cannot delete a thing type if it has things associated with it. To delete
    a thing type, first mark it as deprecated by calling DeprecateThingType, then remove any associated things by
    calling UpdateThing to change the thing type on any associated thing, and finally use DeleteThingType to delete
    the thing type.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        thing_type_name(Text): The name of the thing type.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

