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

hub.exec.boto3.client.proton.create_service_template_version
hub.exec.boto3.client.proton.delete_service_template_version
hub.exec.boto3.client.proton.get_service_template_version
hub.exec.boto3.client.proton.list_service_template_versions
hub.exec.boto3.client.proton.update_service_template_version
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, compatible_environment_templates: List, 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 a service template. A major version of a service template is a version
    that isn't backwards compatible. A minor version of a service 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 service template version that the first request created. Defaults to None.
        compatible_environment_templates(List): An array of compatible environment template objects for the new version of a service template.
        description(Text, optional): A description of the new version of a service template. Defaults to None.
        major_version(Text, optional): To create a new minor version of the service template, include a majorVersion. To create a new
            major and minor version of the service 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 a
            service template.
        tags(List, optional): Create tags for a new version of a service template. Defaults to None.
        template_name(Text): The name of the service template.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.proton.create_service_template_version(
                ctx,
                
                
                **{"clientToken": client_token, "compatibleEnvironmentTemplates": compatible_environment_templates, "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_service_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 a service template exist, delete a major version of the service template if it's
    not the Recommended version. Delete the Recommended version of the service template if no other major versions
    or minor versions of the service template exist. A major version of a service template is a version that isn't
    backwards compatible. Delete a minor version of a service template if it's not the Recommended version. Delete a
    Recommended minor version of the service template if no other minor versions of the service template exist. A
    minor version of a service 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 service template major version to delete.
        minor_version(Text): The service template minor version to delete.
        template_name(Text): The name of the service template.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.proton.service_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.service_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_service_template_version(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.proton.delete_service_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_service_template_version(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

