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

hub.exec.boto3.client.proton.create_environment
hub.exec.boto3.client.proton.delete_environment
hub.exec.boto3.client.proton.get_environment
hub.exec.boto3.client.proton.list_environments
hub.exec.boto3.client.proton.update_environment
"""



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, description: Text = None, environment_account_connection_id: Text = None, proton_service_role_arn: Text = None, tags: List = None, template_minor_version: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deploy a new environment. An AWS Proton environment is created from an environment template that defines
    infrastructure and resources that can be shared across services. For more information, see the Environments in
    the AWS Proton Administrator Guide.

    Args:
        name(Text): The name of the environment.
        description(Text, optional): A description of the environment that's being created and deployed. Defaults to None.
        environment_account_connection_id(Text, optional): The ID of the environment account connection that you provide if you're provisioning your
            environment infrastructure resources to an environment account. You must include either the
            environmentAccountConnectionId or protonServiceRoleArn parameter and value. For more
            information, see Environment account connections in the AWS Proton Administrator guide. Defaults to None.
        proton_service_role_arn(Text, optional): The Amazon Resource Name (ARN) of the AWS Proton service role that allows AWS Proton to make
            calls to other services on your behalf. You must include either the
            environmentAccountConnectionId or protonServiceRoleArn parameter and value. Defaults to None.
        spec(Text): A link to a YAML formatted spec file that provides inputs as defined in the environment template
            bundle schema file. For more information, see Environments in the AWS Proton Administrator
            Guide.
        tags(List, optional): Create tags for your environment. 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 environment template.
        template_minor_version(Text, optional): The ID of the minor version of the environment template. Defaults to None.
        template_name(Text): The name of the environment template. For more information, see Environment Templates in the AWS
            Proton Administrator Guide.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.proton.environment.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.environment.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(name)

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

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

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

