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

hub.exec.boto3.client.codestar.create_user_profile
hub.exec.boto3.client.codestar.delete_user_profile
hub.exec.boto3.client.codestar.describe_user_profile
hub.exec.boto3.client.codestar.list_user_profiles
hub.exec.boto3.client.codestar.update_user_profile
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, user_arn: Text, display_name: Text, email_address: Text, ssh_public_key: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a profile for a user that includes user preferences, such as the display name and email address
    assocciated with the user, in AWS CodeStar. The user profile is not project-specific. Information in the user
    profile is displayed wherever the user's information appears to other users in AWS CodeStar.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        user_arn(Text): The Amazon Resource Name (ARN) of the user in IAM.
        display_name(Text): The name that will be displayed as the friendly name for the user in AWS CodeStar.
        email_address(Text): The email address that will be displayed as part of the user's profile in AWS CodeStar.
        ssh_public_key(Text, optional): The SSH public key associated with the user in AWS CodeStar. If a project owner allows the user
            remote access to project resources, this public key will be used along with the user's private
            key for SSH access. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.codestar.create_user_profile(
                ctx,
                
                
                **{"userArn": user_arn, "displayName": display_name, "emailAddress": email_address, "sshPublicKey": ssh_public_key}
            )
            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.describe_user_profile(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, user_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a user profile in AWS CodeStar, including all personal preference data associated with that profile,
    such as display name and email address. It does not delete the history of that user, for example the history of
    commits made by that user.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

