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

hub.exec.boto3.client.proton.create_service
hub.exec.boto3.client.proton.delete_service
hub.exec.boto3.client.proton.get_service
hub.exec.boto3.client.proton.list_services
hub.exec.boto3.client.proton.update_service
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, spec: Text, template_major_version: Text, template_name: Text, branch_name: Text = None, description: Text = None, repository_connection_arn: Text = None, repository_id: Text = None, tags: List = None, template_minor_version: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Create an AWS Proton service. An AWS Proton service is an instantiation of a service template and often includes
    several service instances and pipeline. For more information, see Services in the AWS Proton Administrator Guide
    and Services in the AWS Proton User Guide.

    Args:
        name(Text): The service name.
        branch_name(Text, optional): The name of the code repository branch that holds the code that's deployed in AWS Proton. Don't
            include this parameter if your service template doesn't include a service pipeline. Defaults to None.
        description(Text, optional): A description of the AWS Proton service. Defaults to None.
        repository_connection_arn(Text, optional): The Amazon Resource Name (ARN) of the repository connection. For more information, see Set up
            repository connection in the AWS Proton Administrator Guide and Setting up with AWS Proton in
            the AWS Proton User Guide. Don't include this parameter if your service template doesn't include
            a service pipeline. Defaults to None.
        repository_id(Text, optional): The ID of the code repository. Don't include this parameter if your service template doesn't
            include a service pipeline. Defaults to None.
        spec(Text): A link to a spec file that provides inputs as defined in the service template bundle schema
            file. The spec file is in YAML format. Don’t include pipeline inputs in the spec if your service
            template doesn’t include a service pipeline. For more information, see Create a service in the
            AWS Proton Administrator Guide and Create a service in the AWS Proton User Guide.
        tags(List, optional): Create tags for your service. For more information, see AWS Proton resources and tagging in the
            AWS Proton Administrator Guide or AWS Proton User Guide. Defaults to None.
        template_major_version(Text): The ID of the major version of the service template that was used to create the service.
        template_minor_version(Text, optional): The ID of the minor version of the service template that was used to create the service. Defaults to None.
        template_name(Text): The name of the service template that's used to create the service.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.proton.create_service(
                ctx,
                
                
                **{"Name": name, "branchName": branch_name, "description": description, "repositoryConnectionArn": repository_connection_arn, "repositoryId": repository_id, "spec": spec, "tags": tags, "templateMajorVersion": template_major_version, "templateMinorVersion": template_minor_version, "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(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Delete a service.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

