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

hub.exec.boto3.client.kendra.create_index
hub.exec.boto3.client.kendra.delete_index
hub.exec.boto3.client.kendra.describe_index
hub.exec.boto3.client.kendra.update_index
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, role_arn: Text, edition: Text = None, server_side_encryption_configuration: Dict = None, description: Text = None, tags: List = None, user_token_configurations: List = None, user_context_policy: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new Amazon Kendra index. Index creation is an asynchronous operation. To determine if index creation
    has completed, check the Status field returned from a call to DescribeIndex. The Status field is set to ACTIVE
    when the index is ready to use. Once the index is active you can index your documents using the BatchPutDocument
    operation or using one of the supported data sources.

    Args:
        name(Text): The name for the new index.
        edition(Text, optional): The Amazon Kendra edition to use for the index. Choose DEVELOPER_EDITION for indexes intended
            for development, testing, or proof of concept. Use ENTERPRISE_EDITION for your production
            databases. Once you set the edition for an index, it can't be changed. The Edition parameter is
            optional. If you don't supply a value, the default is ENTERPRISE_EDITION. For more information
            on quota limits for enterprise and developer editions, see Quotas. Defaults to None.
        role_arn(Text): An Identity and Access Management(IAM) role that gives Amazon Kendra permissions to access your
            Amazon CloudWatch logs and metrics. This is also the role used when you use the BatchPutDocument
            operation to index documents from an Amazon S3 bucket.
        server_side_encryption_configuration(Dict, optional): The identifier of the KMScustomer managed key (CMK) to use to encrypt data indexed by Amazon
            Kendra. Amazon Kendra doesn't support asymmetric CMKs. Defaults to None.
        description(Text, optional): A description for the index. Defaults to None.
        tags(List, optional): A list of key-value pairs that identify the index. You can use the tags to identify and organize
            your resources and to control access to resources. Defaults to None.
        user_token_configurations(List, optional): The user token configuration. Defaults to None.
        user_context_policy(Text, optional): The user context policy.  ATTRIBUTE_FILTER  All indexed content is searchable and displayable
            for all users. If there is an access control list, it is ignored. You can filter on user and
            group attributes.   USER_TOKEN  Enables SSO and token-based user access control. All documents
            with no access control and all documents accessible to the user will be searchable and
            displayable. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.kendra.create_index(
                ctx,
                
                ClientToken=name,
                **{"Name": name, "Edition": edition, "RoleArn": role_arn, "ServerSideEncryptionConfiguration": server_side_encryption_configuration, "Description": description, "Tags": tags, "UserTokenConfigurations": user_token_configurations, "UserContextPolicy": user_context_policy}
            )
            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_index(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, id_: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an existing Amazon Kendra index. An exception is not thrown if the index is already being deleted. While
    the index is being deleted, the Status field returned by a call to the DescribeIndex operation is set to
    DELETING.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

