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

hub.exec.boto3.client.iot1click_projects.create_project
hub.exec.boto3.client.iot1click_projects.delete_project
hub.exec.boto3.client.iot1click_projects.describe_project
hub.exec.boto3.client.iot1click_projects.list_projects
hub.exec.boto3.client.iot1click_projects.update_project
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, project_name: Text, description: Text = None, placement_template: Dict = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an empty project with a placement template. A project contains zero or more placements that adhere to
    the placement template defined in the project.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        project_name(Text): The name of the project to create.
        description(Text, optional): An optional description for the project. Defaults to None.
        placement_template(Dict, optional): The schema defining the placement to be created. A placement template defines placement default
            attributes and device templates. You cannot add or remove device templates after the project has
            been created. However, you can update callbackOverrides for the device templates using the
            UpdateProject API. Defaults to None.
        tags(Dict, optional): Optional tags (metadata key/value pairs) to be associated with the project. For example, {
            {"key1": "value1", "key2": "value2"} }. For more information, see AWS Tagging Strategies. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iot1click_projects.create_project(
                ctx,
                
                
                **{"projectName": project_name, "description": description, "placementTemplate": placement_template, "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.iot1click_projects.describe_project(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, project_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a project. To delete a project, it must not have any placements associated with it.  When you delete a
    project, all associated data becomes irretrievable.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        project_name(Text): The name of the empty project to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

