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

hub.exec.boto3.client.location.associate_tracker_consumer
hub.exec.boto3.client.location.disassociate_tracker_consumer
hub.exec.boto3.client.location.list_tracker_consumers
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, consumer_arn: Text, tracker_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an association between a geofence collection and a tracker resource. This allows the tracker resource to
    communicate location data to the linked geofence collection.  You can associate up to five geofence collections
    to each tracker resource.  Currently not supported — Cross-account configurations, such as creating associations
    between a tracker resource in one account and a geofence collection in another account.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        consumer_arn(Text): The Amazon Resource Name (ARN) for the geofence collection to be associated to tracker resource.
            Used when you need to specify a resource across all AWS.   Format example:
            arn:aws:geo:region:account-id:geofence-collection/ExampleGeofenceCollectionConsumer.
        tracker_name(Text): The name of the tracker resource to be associated with a geofence collection.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.location.tracker_consumer.present:
                - name: value
                - consumer_arn: value
                - tracker_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.location.tracker_consumer.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.location.list_tracker_consumers(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.location.associate_tracker_consumer(
                ctx,
                
                
                **{"ConsumerArn": consumer_arn, "TrackerName": tracker_name}
            )
            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.location.list_tracker_consumers(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, consumer_arn: Text, tracker_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes the association between a tracker resource and a geofence collection.  Once you unlink a tracker
    resource from a geofence collection, the tracker positions will no longer be automatically evaluated against
    geofences.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        consumer_arn(Text): The Amazon Resource Name (ARN) for the geofence collection to be disassociated from the tracker
            resource. Used when you need to specify a resource across all AWS.    Format example:
            arn:aws:geo:region:account-id:geofence-collection/ExampleGeofenceCollectionConsumer.
        tracker_name(Text): The name of the tracker resource to be dissociated from the consumer.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.location.tracker_consumer.absent:
                - name: value
                - consumer_arn: value
                - tracker_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.location.tracker_consumer.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.location.list_tracker_consumers(name)

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

