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

hub.exec.boto3.client.license_manager.checkout_license
hub.exec.boto3.client.license_manager.create_license
hub.exec.boto3.client.license_manager.delete_license
hub.exec.boto3.client.license_manager.get_license
hub.exec.boto3.client.license_manager.list_licenses
"""



from typing import *
import dict_tools.differ as differ


__virtualname__ = "license"
async def present(hub, ctx, name: Text, license_name: Text, product_name: Text, product_sku: Text, issuer: Dict, home_region: Text, validity: Dict, entitlements: List, beneficiary: Text, consumption_configuration: Dict, license_metadata: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a license.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        license_name(Text): License name.
        product_name(Text): Product name.
        product_sku(Text): Product SKU.
        issuer(Dict): License issuer.
        home_region(Text): Home Region for the license.
        validity(Dict): Date and time range during which the license is valid, in ISO8601-UTC format.
        entitlements(List): License entitlements.
        beneficiary(Text): License beneficiary.
        consumption_configuration(Dict): Configuration for consumption of the license. Choose a provisional configuration for workloads
            running with continuous connectivity. Choose a borrow configuration for workloads with offline
            usage.
        license_metadata(List, optional): Information about the license. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.license_manager.license_.present:
                - name: value
                - license_name: value
                - product_name: value
                - product_sku: value
                - issuer: value
                - home_region: value
                - validity: value
                - entitlements: value
                - beneficiary: value
                - consumption_configuration: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.license_manager.license.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_license(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.license_manager.create_license(
                ctx,
                
                ClientToken=name,
                **{"LicenseName": license_name, "ProductName": product_name, "ProductSKU": product_sku, "Issuer": issuer, "HomeRegion": home_region, "Validity": validity, "Entitlements": entitlements, "Beneficiary": beneficiary, "ConsumptionConfiguration": consumption_configuration, "LicenseMetadata": license_metadata}
            )
            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_license(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, license_arn: Text, source_version: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes 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.
        source_version(Text): Current version of the license.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

