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

hub.exec.boto3.client.kendra.create_thesaurus
hub.exec.boto3.client.kendra.delete_thesaurus
hub.exec.boto3.client.kendra.describe_thesaurus
hub.exec.boto3.client.kendra.update_thesaurus
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, index_id: Text, role_arn: Text, source_s3_path: Dict, description: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a thesaurus for an index. The thesaurus contains a list of synonyms in Solr format.

    Args:
        name(Text): The name for the new thesaurus.
        index_id(Text): The unique identifier of the index for the new thesaurus.
        description(Text, optional): The description for the new thesaurus. Defaults to None.
        role_arn(Text): An AWS Identity and Access Management (IAM) role that gives Amazon Kendra permissions to access
            thesaurus file specified in SourceS3Path.
        tags(List, optional): A list of key-value pairs that identify the thesaurus. You can use the tags to identify and
            organize your resources and to control access to resources. Defaults to None.
        source_s3_path(Dict): The thesaurus file Amazon S3 source path.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, id_: Text, index_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an existing Amazon Kendra thesaurus.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        id_(Text): The identifier of the thesaurus to delete.
        index_id(Text): The identifier of the index associated with the thesaurus to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

