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

hub.exec.boto3.client.codestar.associate_team_member
hub.exec.boto3.client.codestar.disassociate_team_member
hub.exec.boto3.client.codestar.list_team_members
hub.exec.boto3.client.codestar.update_team_member
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, project_id: Text, user_arn: Text, project_role: Text, client_request_token: Text = None, remote_access_allowed: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Adds an IAM user to the team for an AWS CodeStar project.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        project_id(Text): The ID of the project to which you will add the IAM user.
        client_request_token(Text, optional): A user- or system-generated token that identifies the entity that requested the team member
            association to the project. This token can be used to repeat the request. Defaults to None.
        user_arn(Text): The Amazon Resource Name (ARN) for the IAM user you want to add to the AWS CodeStar project.
        project_role(Text): The AWS CodeStar project role that will apply to this user. This role determines what actions a
            user can take in an AWS CodeStar project.
        remote_access_allowed(bool, optional): Whether the team member is allowed to use an SSH public/private key pair to remotely access
            project resources, for example Amazon EC2 instances. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.codestar.team_member.present:
                - name: value
                - project_id: value
                - user_arn: value
                - project_role: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.codestar.team_member.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.codestar.list_team_members(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.codestar.associate_team_member(
                ctx,
                
                
                **{"projectId": project_id, "clientRequestToken": client_request_token, "userArn": user_arn, "projectRole": project_role, "remoteAccessAllowed": remote_access_allowed}
            )
            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.codestar.list_team_members(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, project_id: Text, user_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes a user from a project. Removing a user from a project also removes the IAM policies from that user that
    allowed access to the project and its resources. Disassociating a team member does not remove that user's
    profile from AWS CodeStar. It does not remove the user from IAM.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        project_id(Text): The ID of the AWS CodeStar project from which you want to remove a team member.
        user_arn(Text): The Amazon Resource Name (ARN) of the IAM user or group whom you want to remove from the
            project.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

