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

hub.exec.boto3.client.iotsitewise.create_gateway
hub.exec.boto3.client.iotsitewise.delete_gateway
hub.exec.boto3.client.iotsitewise.describe_gateway
hub.exec.boto3.client.iotsitewise.list_gateways
hub.exec.boto3.client.iotsitewise.update_gateway
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, gateway_name: Text, gateway_platform: Dict, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a gateway, which is a virtual or edge device that delivers industrial data streams from local servers to
    IoT SiteWise. For more information, see Ingesting data using a gateway in the IoT SiteWise User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        gateway_name(Text): A unique, friendly name for the gateway.
        gateway_platform(Dict): The gateway's platform. You can only specify one platform in a gateway.
        tags(Dict, optional): A list of key-value pairs that contain metadata for the gateway. 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.gateway.present:
                - name: value
                - gateway_name: value
                - gateway_platform: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iotsitewise.gateway.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_gateway(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iotsitewise.create_gateway(
                ctx,
                
                
                **{"gatewayName": gateway_name, "gatewayPlatform": gateway_platform, "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_gateway(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, gateway_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a gateway from IoT SiteWise. When you delete a gateway, some of the gateway's files remain in your
    gateway's file system.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

