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

hub.exec.boto3.client.proton.accept_environment_account_connection
hub.exec.boto3.client.proton.create_environment_account_connection
hub.exec.boto3.client.proton.delete_environment_account_connection
hub.exec.boto3.client.proton.get_environment_account_connection
hub.exec.boto3.client.proton.list_environment_account_connections
hub.exec.boto3.client.proton.reject_environment_account_connection
hub.exec.boto3.client.proton.update_environment_account_connection
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, environment_name: Text, management_account_id: Text, role_arn: Text, client_token: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Create an environment account connection in an environment account so that environment infrastructure resources
    can be provisioned in the environment account from a management account. An environment account connection is a
    secure bi-directional connection between a management account and an environment account that maintains
    authorization and permissions. For more information, see Environment account connections in the AWS Proton
    Administrator guide.

    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 account connection that the first request created. Defaults to None.
        environment_name(Text): The name of the AWS Proton environment that's created in the associated management account.
        management_account_id(Text): The ID of the management account that accepts or rejects the environment account connection. You
            create an manage the AWS Proton environment in this account. If the management account accepts
            the environment account connection, AWS Proton can use the associated IAM role to provision
            environment infrastructure resources in the associated environment account.
        role_arn(Text): The Amazon Resource Name (ARN) of the IAM service role that's created in the environment
            account. AWS Proton uses this role to provision infrastructure resources in the associated
            environment account.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.proton.create_environment_account_connection(
                ctx,
                
                
                **{"clientToken": client_token, "environmentName": environment_name, "managementAccountId": management_account_id, "roleArn": role_arn}
            )
            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_account_connection(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, id_: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    In an environment account, delete an environment account connection. After you delete an environment account
    connection that’s in use by an AWS Proton environment, AWS Proton can’t manage the environment infrastructure
    resources until a new environment account connection is accepted for the environment account and associated
    environment. You're responsible for cleaning up provisioned resources that remain without an environment
    connection. For more information, see Environment account connections in the AWS Proton Administrator guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        id_(Text): The ID of the environment account connection to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

