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

hub.exec.boto3.client.greengrass.create_device_definition
hub.exec.boto3.client.greengrass.delete_device_definition
hub.exec.boto3.client.greengrass.get_device_definition
hub.exec.boto3.client.greengrass.list_device_definitions
hub.exec.boto3.client.greengrass.update_device_definition
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text = None, amzn_client_token: Text = None, initial_version: Dict = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a device definition. You may provide the initial version of the device definition now or use
    ''CreateDeviceDefinitionVersion'' at a later time.

    Args:
        name(Text, optional): The name of the device definition. Defaults to None.
        amzn_client_token(Text, optional): A client token used to correlate requests and responses. Defaults to None.
        initial_version(Dict, optional): Information about the initial version of the device definition. Defaults to None.
        tags(Dict, optional): Tag(s) to add to the new resource. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.greengrass.create_device_definition(
                ctx,
                
                
                **{"Name": name, "AmznClientToken": amzn_client_token, "InitialVersion": initial_version, "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.greengrass.get_device_definition(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, device_definition_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a device definition.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        device_definition_id(Text): The ID of the device definition.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

