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

hub.exec.boto3.client.worklink.create_fleet
hub.exec.boto3.client.worklink.delete_fleet
hub.exec.boto3.client.worklink.list_fleets
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, fleet_name: Text, display_name: Text = None, optimize_for_end_user_location: bool = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a fleet. A fleet consists of resources and the configuration that delivers associated websites to
    authorized users who download and set up the Amazon WorkLink app.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        fleet_name(Text): A unique name for the fleet.
        display_name(Text, optional): The fleet name to display. Defaults to None.
        optimize_for_end_user_location(bool, optional): The option to optimize for better performance by routing traffic through the closest AWS Region
            to users, which may be outside of your home Region. Defaults to None.
        tags(Dict, optional):  The tags to add to the resource. A tag is a key-value pair. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.worklink.create_fleet(
                ctx,
                
                
                **{"FleetName": fleet_name, "DisplayName": display_name, "OptimizeForEndUserLocation": optimize_for_end_user_location, "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.worklink.list_fleets(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, fleet_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a fleet. Prevents users from accessing previously associated websites.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        fleet_arn(Text): The ARN of the fleet.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

