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

hub.exec.boto3.client.proton.create_service_template
hub.exec.boto3.client.proton.delete_service_template
hub.exec.boto3.client.proton.get_service_template
hub.exec.boto3.client.proton.list_service_templates
hub.exec.boto3.client.proton.update_service_template
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, description: Text = None, display_name: Text = None, encryption_key: Text = None, pipeline_provisioning: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Create a service template. The administrator creates a service template to define standardized infrastructure
    and an optional CICD service pipeline. Developers, in turn, select the service template from AWS Proton. If the
    selected service template includes a service pipeline definition, they provide a link to their source code
    repository. AWS Proton then deploys and manages the infrastructure defined by the selected service template. For
    more information, see Service Templates in the AWS Proton Administrator Guide.

    Args:
        name(Text): The name of the service template.
        description(Text, optional): A description of the service template. Defaults to None.
        display_name(Text, optional): The name of the service template as displayed in the developer interface. Defaults to None.
        encryption_key(Text, optional): A customer provided encryption key that's used to encrypt data. Defaults to None.
        pipeline_provisioning(Text, optional): AWS Proton includes a service pipeline for your service by default. When included, this
            parameter indicates that an AWS Proton service pipeline won't be included for your service. Once
            specified, this parameter can't be changed. For more information, see Service template bundles
            in the AWS Proton Administrator Guide. Defaults to None.
        tags(List, optional): Create tags for your service template. For more information, see AWS Proton resources and
            tagging in the AWS Proton Administrator Guide or AWS Proton User Guide. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.proton.create_service_template(
                ctx,
                
                
                **{"Name": name, "description": description, "displayName": display_name, "encryptionKey": encryption_key, "pipelineProvisioning": pipeline_provisioning, "tags": tags}
            )
            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(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    If no other major or minor versions of the service template exist, delete the service template.

    Args:
        name(Text): The name of the service template to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

