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

hub.exec.boto3.client.quicksight.create_iam_policy_assignment
hub.exec.boto3.client.quicksight.delete_iam_policy_assignment
hub.exec.boto3.client.quicksight.describe_iam_policy_assignment
hub.exec.boto3.client.quicksight.list_iam_policy_assignments
hub.exec.boto3.client.quicksight.update_iam_policy_assignment
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, aws_account_id: Text, assignment_name: Text, assignment_status: Text, namespace: Text, policy_arn: Text = None, identities: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an assignment with one specified IAM policy, identified by its Amazon Resource Name (ARN). This policy
    assignment is attached to the specified groups or users of Amazon QuickSight. Assignment names are unique per
    Amazon Web Services account;. To avoid overwriting rules in other namespaces, use assignment names that are
    unique.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        aws_account_id(Text): The ID of the Amazon Web Services account; where you want to assign an IAM policy to QuickSight
            users or groups.
        assignment_name(Text): The name of the assignment, also called a rule. It must be unique within an Amazon Web Services
            account;.
        assignment_status(Text): The status of the assignment. Possible values are as follows:    ENABLED - Anything specified in
            this assignment is used when creating the data source.    DISABLED - This assignment isn't used
            when creating the data source.    DRAFT - This assignment is an unfinished draft and isn't used
            when creating the data source.
        policy_arn(Text, optional): The ARN for the IAM policy to apply to the QuickSight users and groups specified in this
            assignment. Defaults to None.
        identities(Dict, optional): The QuickSight users, groups, or both that you want to assign the policy to. Defaults to None.
        namespace(Text): The namespace that contains the assignment.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.quicksight.create_iam_policy_assignment(
                ctx,
                
                
                **{"AwsAccountId": aws_account_id, "AssignmentName": assignment_name, "AssignmentStatus": assignment_status, "PolicyArn": policy_arn, "Identities": identities, "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.describe_iam_policy_assignment(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, aws_account_id: Text, assignment_name: Text, namespace: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an existing IAM policy assignment.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        aws_account_id(Text): The Amazon Web Services account; ID where you want to delete the IAM policy assignment.
        assignment_name(Text): The name of the assignment.
        namespace(Text): The namespace that contains the assignment.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

