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

hub.exec.boto3.client.devicefarm.create_device_pool
hub.exec.boto3.client.devicefarm.delete_device_pool
hub.exec.boto3.client.devicefarm.get_device_pool
hub.exec.boto3.client.devicefarm.list_device_pools
hub.exec.boto3.client.devicefarm.update_device_pool
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, project_arn: Text, rules: List, description: Text = None, max_devices: int = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a device pool.

    Args:
        name(Text): The device pool's name.
        project_arn(Text): The ARN of the project for the device pool.
        description(Text, optional): The device pool's description. Defaults to None.
        rules(List): The device pool's rules.
        max_devices(int, optional): The number of devices that Device Farm can add to your device pool. Device Farm adds devices
            that are available and meet the criteria that you assign for the rules parameter. Depending on
            how many devices meet these constraints, your device pool might contain fewer devices than the
            value for this parameter. By specifying the maximum number of devices, you can control the costs
            that you incur by running tests. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.devicefarm.device_pool.present:
                - name: value
                - project_arn: value
                - rules: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.devicefarm.device_pool.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.devicefarm.get_device_pool(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.devicefarm.create_device_pool(
                ctx,
                
                
                **{"Name": name, "projectArn": project_arn, "description": description, "rules": rules, "maxDevices": max_devices}
            )
            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.devicefarm.get_device_pool(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a device pool given the pool ARN. Does not allow deletion of curated pools owned by the system.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        arn(Text): Represents the Amazon Resource Name (ARN) of the Device Farm device pool to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

