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

hub.exec.boto3.client.mobile.create_project
hub.exec.boto3.client.mobile.delete_project
hub.exec.boto3.client.mobile.describe_project
hub.exec.boto3.client.mobile.export_project
hub.exec.boto3.client.mobile.list_projects
hub.exec.boto3.client.mobile.update_project
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text = None, region: Text = None, contents: ByteString = None, snapshot_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Creates an AWS Mobile Hub project.

    Args:
        name(Text, optional):  Name of the project. Defaults to None.
        region(Text, optional):  Default region where project resources should be created. Defaults to None.
        contents(ByteString, optional):  ZIP or YAML file which contains configuration settings to be used when creating the project.
            This may be the contents of the file downloaded from the URL provided in an export project
            operation. Defaults to None.
        snapshot_id(Text, optional):  Unique identifier for an exported snapshot of project configuration. This snapshot identifier
            is included in the share URL when a project is exported. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.mobile.create_project(
                ctx,
                
                
                **{"Name": name, "region": region, "contents": contents, "snapshotId": snapshot_id}
            )
            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.mobile.describe_project(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, project_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Delets a project in AWS Mobile Hub.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        project_id(Text):  Unique project identifier.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

