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

hub.exec.boto3.client.ec2.create_launch_template_version
hub.exec.boto3.client.ec2.delete_launch_template_versions
hub.exec.boto3.client.ec2.describe_launch_template_versions
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, launch_template_data: Dict, launch_template_id: Text = None, launch_template_name: Text = None, source_version: Text = None, version_description: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new version for a launch template. You can specify an existing version of launch template from which
    to base the new version. Launch template versions are numbered in the order in which they are created. You
    cannot specify, change, or replace the numbering of launch template versions. For more information, see Managing
    launch template versionsin the Amazon Elastic Compute Cloud User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        launch_template_id(Text, optional): The ID of the launch template. You must specify either the launch template ID or launch template
            name in the request. Defaults to None.
        launch_template_name(Text, optional): The name of the launch template. You must specify either the launch template ID or launch
            template name in the request. Defaults to None.
        source_version(Text, optional): The version number of the launch template version on which to base the new version. The new
            version inherits the same launch parameters as the source version, except for parameters that
            you specify in LaunchTemplateData. Snapshots applied to the block device mapping are ignored
            when creating a new version unless they are explicitly included. Defaults to None.
        version_description(Text, optional): A description for the version of the launch template. Defaults to None.
        launch_template_data(Dict): The information for the launch template.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.create_launch_template_version(
                ctx,
                DryRun=ctx.test,
                ClientToken=name,
                **{"LaunchTemplateId": launch_template_id, "LaunchTemplateName": launch_template_name, "SourceVersion": source_version, "VersionDescription": version_description, "LaunchTemplateData": launch_template_data}
            )
            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.ec2.describe_launch_template_versions(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, versions: List, launch_template_id: Text = None, launch_template_name: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes one or more versions of a launch template. You cannot delete the default version of a launch template;
    you must first assign a different version as the default. If the default version is the only version for the
    launch template, you must delete the entire launch template using DeleteLaunchTemplate.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        launch_template_id(Text, optional): The ID of the launch template. You must specify either the launch template ID or launch template
            name in the request. Defaults to None.
        launch_template_name(Text, optional): The name of the launch template. You must specify either the launch template ID or launch
            template name in the request. Defaults to None.
        versions(List): The version numbers of one or more launch template versions to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.delete_launch_template_versions(
                ctx,
                DryRun=ctx.test,
                
                **{"LaunchTemplateId": launch_template_id, "LaunchTemplateName": launch_template_name, "Versions": versions}
            )
            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.ec2.describe_launch_template_versions(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

