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

hub.exec.boto3.client.iotthingsgraph.create_flow_template
hub.exec.boto3.client.iotthingsgraph.delete_flow_template
hub.exec.boto3.client.iotthingsgraph.deprecate_flow_template
hub.exec.boto3.client.iotthingsgraph.get_flow_template
hub.exec.boto3.client.iotthingsgraph.search_flow_templates
hub.exec.boto3.client.iotthingsgraph.update_flow_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 workflow template. Workflows can be created only in the user's namespace. (The public namespace
    contains only entities.) The workflow can contain only entities in the specified namespace. The workflow 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 workflow DefinitionDocument.
        compatible_namespace_version(int, optional): The namespace version in which the workflow 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.flow_template.present:
                - name: value
                - definition: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iotthingsgraph.flow_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_flow_template(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iotthingsgraph.create_flow_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_flow_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 workflow. Any new system or deployment that contains this workflow will fail to update or deploy.
    Existing deployments that contain the workflow will continue to run (since they use a snapshot of the workflow
    taken at the time of deployment).

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

