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

hub.exec.boto3.client.quicksight.create_group_membership
hub.exec.boto3.client.quicksight.delete_group_membership
hub.exec.boto3.client.quicksight.list_group_memberships
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, member_name: Text, group_name: Text, aws_account_id: Text, namespace: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Adds an Amazon QuickSight user to an Amazon QuickSight group.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        member_name(Text): The name of the user that you want to add to the group membership.
        group_name(Text): The name of the group that you want to add the user to.
        aws_account_id(Text): The ID for the Amazon Web Services account; that the group is in. Currently, you use the ID for
            the Amazon Web Services account; that contains your Amazon QuickSight account.
        namespace(Text): The namespace. Currently, you should set this to default.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.quicksight.group_membership.present:
                - name: value
                - member_name: value
                - group_name: value
                - aws_account_id: value
                - namespace: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.quicksight.group_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.quicksight.list_group_memberships(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.quicksight.create_group_membership(
                ctx,
                
                
                **{"MemberName": member_name, "GroupName": group_name, "AwsAccountId": aws_account_id, "Namespace": namespace}
            )
            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.quicksight.list_group_memberships(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, member_name: Text, group_name: Text, aws_account_id: Text, namespace: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes a user from a group so that the user is no longer a member of the group.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        member_name(Text): The name of the user that you want to delete from the group membership.
        group_name(Text): The name of the group that you want to delete the user from.
        aws_account_id(Text): The ID for the Amazon Web Services account; that the group is in. Currently, you use the ID for
            the Amazon Web Services account; that contains your Amazon QuickSight account.
        namespace(Text): The namespace. Currently, you should set this to default.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.quicksight.group_membership.absent:
                - name: value
                - member_name: value
                - group_name: value
                - aws_account_id: value
                - namespace: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.quicksight.group_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.quicksight.list_group_memberships(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.quicksight.delete_group_membership(
                ctx,
                
                
                **{"MemberName": member_name, "GroupName": group_name, "AwsAccountId": aws_account_id, "Namespace": namespace}
            )
            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.quicksight.list_group_memberships(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

