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

hub.exec.boto3.client.ec2.create_launch_template
hub.exec.boto3.client.ec2.delete_launch_template
hub.exec.boto3.client.ec2.describe_launch_templates
hub.exec.boto3.client.ec2.modify_launch_template
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, launch_template_name: Text, launch_template_data: Dict, version_description: Text = None, tag_specifications: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a launch template. A launch template contains the parameters to launch an instance. When you launch an
    instance using RunInstances, you can specify a launch template instead of providing the launch parameters in the
    request. For more information, see Launching an instance from a launch templatein the Amazon Elastic Compute
    Cloud User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        launch_template_name(Text): A name for the launch template.
        version_description(Text, optional): A description for the first version of the launch template. Defaults to None.
        launch_template_data(Dict): The information for the launch template.
        tag_specifications(List, optional): The tags to apply to the launch template during creation. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, launch_template_id: Text = None, launch_template_name: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a launch template. Deleting a launch template deletes all of its versions.

    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.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

