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

hub.exec.boto3.client.license_manager.create_token
hub.exec.boto3.client.license_manager.delete_token
hub.exec.boto3.client.license_manager.list_tokens
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, license_arn: Text, role_arns: List = None, expiration_in_days: int = None, token_properties: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a long-lived token. A refresh token is a JWT token used to get an access token. With an access token,
    you can call AssumeRoleWithWebIdentity to get role credentials that you can use to call License Manager to
    manage the specified license.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        license_arn(Text): Amazon Resource Name (ARN) of the license. The ARN is mapped to the aud claim of the JWT token.
        role_arns(List, optional): Amazon Resource Name (ARN) of the IAM roles to embed in the token. License Manager does not
            check whether the roles are in use. Defaults to None.
        expiration_in_days(int, optional): Token expiration, in days, counted from token creation. The default is 365 days. Defaults to None.
        token_properties(List, optional): Data specified by the caller to be included in the JWT token. The data is mapped to the amr
            claim of the JWT token. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.license_manager.create_token(
                ctx,
                
                ClientToken=name,
                **{"LicenseArn": license_arn, "RoleArns": role_arns, "ExpirationInDays": expiration_in_days, "TokenProperties": token_properties}
            )
            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.license_manager.list_tokens(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, token_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified token. Must be called in the license home Region.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        token_id(Text): Token ID.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

