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

hub.exec.boto3.client.cloud9.create_environment_membership
hub.exec.boto3.client.cloud9.delete_environment_membership
hub.exec.boto3.client.cloud9.describe_environment_memberships
hub.exec.boto3.client.cloud9.update_environment_membership
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, environment_id: Text, user_arn: Text, permissions: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Adds an environment member to an Cloud9 development environment.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        environment_id(Text): The ID of the environment that contains the environment member you want to add.
        user_arn(Text): The Amazon Resource Name (ARN) of the environment member you want to add.
        permissions(Text): The type of environment member permissions you want to associate with this environment member.
            Available values include:    read-only: Has read-only access to the environment.    read-write:
            Has read-write access to the environment.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.cloud9.environment_membership.present:
                - name: value
                - environment_id: value
                - user_arn: value
                - permissions: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.cloud9.environment_membership.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.cloud9.describe_environment_memberships(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.cloud9.create_environment_membership(
                ctx,
                
                
                **{"environmentId": environment_id, "userArn": user_arn, "permissions": permissions}
            )
            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.cloud9.describe_environment_memberships(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, environment_id: Text, user_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an environment member from an Cloud9 development environment.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        environment_id(Text): The ID of the environment to delete the environment member from.
        user_arn(Text): The Amazon Resource Name (ARN) of the environment member to delete from the environment.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

