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

hub.exec.boto3.client.emr.create_studio_session_mapping
hub.exec.boto3.client.emr.delete_studio_session_mapping
hub.exec.boto3.client.emr.get_studio_session_mapping
hub.exec.boto3.client.emr.list_studio_session_mappings
hub.exec.boto3.client.emr.update_studio_session_mapping
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, studio_id: Text, identity_type: Text, session_policy_arn: Text, identity_id: Text = None, identity_name: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Maps a user or group to the Amazon EMR Studio specified by StudioId, and applies a session policy to refine
    Studio permissions for that user or group.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        studio_id(Text): The ID of the Amazon EMR Studio to which the user or group will be mapped.
        identity_id(Text, optional): The globally unique identifier (GUID) of the user or group from the Amazon Web Services SSO
            Identity Store. For more information, see UserId and GroupId in the Amazon Web Services SSO
            Identity Store API Reference. Either IdentityName or IdentityId must be specified, but not both. Defaults to None.
        identity_name(Text, optional): The name of the user or group. For more information, see UserName and DisplayName in the Amazon
            Web Services SSO Identity Store API Reference. Either IdentityName or IdentityId must be
            specified, but not both. Defaults to None.
        identity_type(Text): Specifies whether the identity to map to the Amazon EMR Studio is a user or a group.
        session_policy_arn(Text): The Amazon Resource Name (ARN) for the session policy that will be applied to the user or group.
            You should specify the ARN for the session policy that you want to apply, not the ARN of your
            user role. For more information, see Create an EMR Studio User Role with Session Policies.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.emr.studio_session_mapping.present:
                - name: value
                - studio_id: value
                - identity_type: value
                - session_policy_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.emr.studio_session_mapping.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.emr.get_studio_session_mapping(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.emr.create_studio_session_mapping(
                ctx,
                
                
                **{"StudioId": studio_id, "IdentityId": identity_id, "IdentityName": identity_name, "IdentityType": identity_type, "SessionPolicyArn": session_policy_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.emr.get_studio_session_mapping(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, studio_id: Text, identity_type: Text, identity_id: Text = None, identity_name: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes a user or group from an Amazon EMR Studio.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        studio_id(Text): The ID of the Amazon EMR Studio.
        identity_id(Text, optional): The globally unique identifier (GUID) of the user or group to remove from the Amazon EMR Studio.
            For more information, see UserId and GroupId in the Amazon Web Services SSO Identity Store API
            Reference. Either IdentityName or IdentityId must be specified. Defaults to None.
        identity_name(Text, optional): The name of the user name or group to remove from the Amazon EMR Studio. For more information,
            see UserName and DisplayName in the Amazon Web Services SSO Store API Reference. Either
            IdentityName or IdentityId must be specified. Defaults to None.
        identity_type(Text): Specifies whether the identity to delete from the Amazon EMR Studio is a user or a group.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.emr.delete_studio_session_mapping(
                ctx,
                
                
                **{"StudioId": studio_id, "IdentityId": identity_id, "IdentityName": identity_name, "IdentityType": identity_type}
            )
            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.emr.get_studio_session_mapping(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

