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

hub.exec.boto3.client.kendra.create_query_suggestions_block_list
hub.exec.boto3.client.kendra.delete_query_suggestions_block_list
hub.exec.boto3.client.kendra.describe_query_suggestions_block_list
hub.exec.boto3.client.kendra.list_query_suggestions_block_lists
hub.exec.boto3.client.kendra.update_query_suggestions_block_list
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, index_id: Text, source_s3_path: Dict, role_arn: Text, description: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a block list to exlcude certain queries from suggestions. Any query that contains words or phrases
    specified in the block list is blocked or filtered out from being shown as a suggestion. You need to provide the
    file location of your block list text file in your S3 bucket. In your text file, enter each block word or phrase
    on a separate line. For information on the current quota limits for block lists, see Quotas for Amazon Kendra.

    Args:
        name(Text): A user friendly name for the block list. For example, the block list named 'offensive-words'
            includes all offensive words that could appear in user queries and need to be blocked from
            suggestions.
        index_id(Text): The identifier of the index you want to create a query suggestions block list for.
        description(Text, optional): A user-friendly description for the block list. For example, the description "List of all
            offensive words that can appear in user queries and need to be blocked from suggestions.". Defaults to None.
        source_s3_path(Dict): The S3 path to your block list text file in your S3 bucket. Each block word or phrase should be
            on a separate line in a text file. For information on the current quota limits for block lists,
            see Quotas for Amazon Kendra.
        role_arn(Text): The IAM (Identity and Access Management) role used by Amazon Kendra to access the block list
            text file in your S3 bucket. You need permissions to the role ARN (Amazon Resource Name). The
            role needs S3 read permissions to your file in S3 and needs to give STS (Security Token Service)
            assume role permissions to Amazon Kendra.
        tags(List, optional): A tag that you can assign to a block list that categorizes the block list. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.kendra.query_suggestions_block_list.present:
                - name: value
                - index_id: value
                - source_s3_path: value
                - role_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.kendra.query_suggestions_block_list.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.kendra.describe_query_suggestions_block_list(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.kendra.create_query_suggestions_block_list(
                ctx,
                
                ClientToken=name,
                **{"Name": name, "IndexId": index_id, "Description": description, "SourceS3Path": source_s3_path, "RoleArn": role_arn, "Tags": tags}
            )
            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.kendra.describe_query_suggestions_block_list(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, index_id: Text, id_: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a block list used for query suggestions for an index. A deleted block list might not take effect right
    away. Amazon Kendra needs to refresh the entire suggestions list to add back the queries that were previously
    blocked.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        index_id(Text): The identifier of the you want to delete a block list from.
        id_(Text): The unique identifier of the block list that needs to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.kendra.query_suggestions_block_list.absent:
                - name: value
                - index_id: value
                - id_: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.kendra.query_suggestions_block_list.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.kendra.describe_query_suggestions_block_list(name)

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

