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

hub.exec.boto3.client.iotsitewise.associate_assets
hub.exec.boto3.client.iotsitewise.create_asset
hub.exec.boto3.client.iotsitewise.delete_asset
hub.exec.boto3.client.iotsitewise.describe_asset
hub.exec.boto3.client.iotsitewise.disassociate_assets
hub.exec.boto3.client.iotsitewise.list_assets
hub.exec.boto3.client.iotsitewise.update_asset
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, asset_name: Text, asset_model_id: Text, client_token: Text = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an asset from an existing asset model. For more information, see Creating assets in the IoT SiteWise
    User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        asset_name(Text): A unique, friendly name for the asset.
        asset_model_id(Text): The ID of the asset model from which to create the asset.
        client_token(Text, optional): A unique case-sensitive identifier that you can provide to ensure the idempotency of the
            request. Don't reuse this client token if a new idempotent request is required. Defaults to None.
        tags(Dict, optional): A list of key-value pairs that contain metadata for the asset. For more information, see Tagging
            your IoT SiteWise resources in the IoT SiteWise User Guide. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.iotsitewise.asset.present:
                - name: value
                - asset_name: value
                - asset_model_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iotsitewise.asset.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.iotsitewise.describe_asset(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iotsitewise.create_asset(
                ctx,
                
                
                **{"assetName": asset_name, "assetModelId": asset_model_id, "clientToken": client_token, "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.iotsitewise.describe_asset(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, asset_id: Text, client_token: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an asset. This action can't be undone. For more information, see Deleting assets and models in the IoT
    SiteWise User Guide.   You can't delete an asset that's associated to another asset. For more information, see
    DisassociateAssets.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        asset_id(Text): The ID of the asset to delete.
        client_token(Text, optional): A unique case-sensitive identifier that you can provide to ensure the idempotency of the
            request. Don't reuse this client token if a new idempotent request is required. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.iotsitewise.delete_asset(
                ctx,
                
                
                **{"assetId": asset_id, "clientToken": client_token}
            )
            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.iotsitewise.describe_asset(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

