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

hub.exec.boto3.client.license_manager.accept_grant
hub.exec.boto3.client.license_manager.create_grant
hub.exec.boto3.client.license_manager.delete_grant
hub.exec.boto3.client.license_manager.get_grant
hub.exec.boto3.client.license_manager.reject_grant
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, grant_name: Text, license_arn: Text, principals: List, home_region: Text, allowed_operations: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a grant for the specified license. A grant shares the use of license entitlements with specific AWS
    accounts.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        grant_name(Text): Grant name.
        license_arn(Text): Amazon Resource Name (ARN) of the license.
        principals(List): The grant principals.
        home_region(Text): Home Region of the grant.
        allowed_operations(List): Allowed operations for the grant.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.license_manager.create_grant(
                ctx,
                
                ClientToken=name,
                **{"GrantName": grant_name, "LicenseArn": license_arn, "Principals": principals, "HomeRegion": home_region, "AllowedOperations": allowed_operations}
            )
            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.get_grant(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, grant_arn: Text, version: Text, status_reason: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified grant.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        grant_arn(Text): Amazon Resource Name (ARN) of the grant.
        status_reason(Text, optional): . Defaults to None.
        version(Text): Current version of the grant.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.license_manager.delete_grant(
                ctx,
                
                
                **{"GrantArn": grant_arn, "StatusReason": status_reason, "Version": version}
            )
            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.get_grant(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

