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

hub.exec.boto3.client.iotthingsgraph.create_system_template
hub.exec.boto3.client.iotthingsgraph.delete_system_template
hub.exec.boto3.client.iotthingsgraph.deprecate_system_template
hub.exec.boto3.client.iotthingsgraph.get_system_template
hub.exec.boto3.client.iotthingsgraph.search_system_templates
hub.exec.boto3.client.iotthingsgraph.update_system_template
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, definition: Dict, compatible_namespace_version: int = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a system. The system is validated against the entities in the latest version of the user's namespace
    unless another namespace version is specified in the request.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        definition(Dict): The DefinitionDocument used to create the system.
        compatible_namespace_version(int, optional): The namespace version in which the system is to be created. If no value is specified, the latest
            version is used by default. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iotthingsgraph.create_system_template(
                ctx,
                
                
                **{"definition": definition, "compatibleNamespaceVersion": compatible_namespace_version}
            )
            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.iotthingsgraph.get_system_template(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, id_: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a system. New deployments can't contain the system after its deletion. Existing deployments that contain
    the system will continue to work because they use a snapshot of the system that is taken when it is deployed.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        id_(Text): The ID of the system to be deleted. The ID should be in the following format.
            urn:tdm:REGION/ACCOUNT ID/default:system:SYSTEMNAME.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

