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

hub.exec.boto3.client.networkmanager.create_device
hub.exec.boto3.client.networkmanager.delete_device
hub.exec.boto3.client.networkmanager.get_devices
hub.exec.boto3.client.networkmanager.update_device
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, global_network_id: Text, aws_location: Dict = None, description: Text = None, type_: Text = None, vendor: Text = None, model: Text = None, serial_number: Text = None, location: Dict = None, site_id: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new device in a global network. If you specify both a site ID and a location, the location of the site
    is used for visualization in the Network Manager console.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        global_network_id(Text): The ID of the global network.
        aws_location(Dict, optional): The AWS location of the device. Defaults to None.
        description(Text, optional): A description of the device. Length Constraints: Maximum length of 256 characters. Defaults to None.
        type_(Text, optional): The type of the device. Defaults to None.
        vendor(Text, optional): The vendor of the device. Length Constraints: Maximum length of 128 characters. Defaults to None.
        model(Text, optional): The model of the device. Length Constraints: Maximum length of 128 characters. Defaults to None.
        serial_number(Text, optional): The serial number of the device. Length Constraints: Maximum length of 128 characters. Defaults to None.
        location(Dict, optional): The location of the device. Defaults to None.
        site_id(Text, optional): The ID of the site. Defaults to None.
        tags(List, optional): The tags to apply to the resource during creation. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.networkmanager.create_device(
                ctx,
                
                
                **{"GlobalNetworkId": global_network_id, "AWSLocation": aws_location, "Description": description, "Type": type_, "Vendor": vendor, "Model": model, "SerialNumber": serial_number, "Location": location, "SiteId": site_id, "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.networkmanager.get_devices(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, global_network_id: Text, device_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an existing device. You must first disassociate the device from any links and customer gateways.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        global_network_id(Text): The ID of the global network.
        device_id(Text): The ID of the device.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.networkmanager.device.absent:
                - name: value
                - global_network_id: value
                - device_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.networkmanager.device.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.networkmanager.get_devices(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.networkmanager.delete_device(
                ctx,
                
                
                **{"GlobalNetworkId": global_network_id, "DeviceId": device_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.networkmanager.get_devices(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

