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

hub.exec.boto3.client.proton.create_environment_template_version
hub.exec.boto3.client.proton.delete_environment_template_version
hub.exec.boto3.client.proton.get_environment_template_version
hub.exec.boto3.client.proton.list_environment_template_versions
hub.exec.boto3.client.proton.update_environment_template_version
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, source: Dict, template_name: Text, client_token: Text = None, description: Text = None, major_version: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Create a new major or minor version of an environment template. A major version of an environment template is a
    version that isn't backwards compatible. A minor version of an environment template is a version that's
    backwards compatible within its major version.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        client_token(Text, optional): When included, if two identicial requests are made with the same client token, AWS Proton
            returns the environment template version that the first request created. Defaults to None.
        description(Text, optional): A description of the new version of an environment template. Defaults to None.
        major_version(Text, optional): To create a new minor version of the environment template, include a majorVersion. To create a
            new major and minor version of the environment template, exclude majorVersion. Defaults to None.
        source(Dict): An object that includes the template bundle S3 bucket path and name for the new version of an
            template.
        tags(List, optional): Create tags for a new version of an environment template. Defaults to None.
        template_name(Text): The name of the environment template.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.proton.environment_template_version.present:
                - name: value
                - source: value
                - template_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.proton.environment_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.proton.get_environment_template_version(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.proton.create_environment_template_version(
                ctx,
                
                
                **{"clientToken": client_token, "description": description, "majorVersion": major_version, "source": source, "tags": tags, "templateName": template_name}
            )
            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.proton.get_environment_template_version(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, major_version: Text, minor_version: Text, template_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    If no other minor versions of an environment template exist, delete a major version of the environment template
    if it's not the Recommended version. Delete the Recommended version of the environment template if no other
    major versions or minor versions of the environment template exist. A major version of an environment template
    is a version that's not backwards compatible. Delete a minor version of an environment template if it isn't the
    Recommended version. Delete a Recommended minor version of the environment template if no other minor versions
    of the environment template exist. A minor version of an environment template is a version that's backwards
    compatible.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        major_version(Text): The environment template major version to delete.
        minor_version(Text): The environment template minor version to delete.
        template_name(Text): The name of the environment template.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.proton.environment_template_version.absent:
                - name: value
                - major_version: value
                - minor_version: value
                - template_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.proton.environment_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.proton.get_environment_template_version(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.proton.delete_environment_template_version(
                ctx,
                
                
                **{"majorVersion": major_version, "minorVersion": minor_version, "templateName": 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.proton.get_environment_template_version(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

