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

hub.exec.boto3.client.kendra.create_data_source
hub.exec.boto3.client.kendra.delete_data_source
hub.exec.boto3.client.kendra.describe_data_source
hub.exec.boto3.client.kendra.list_data_sources
hub.exec.boto3.client.kendra.update_data_source
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, index_id: Text, type_: Text, configuration: Dict = None, description: Text = None, schedule: Text = None, role_arn: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a data source that you use to with an Amazon Kendra index.  You specify a name, data source connector
    type and description for your data source. You also specify configuration information such as document metadata
    (author, source URI, and so on) and user context information.  CreateDataSource is a synchronous operation. The
    operation returns 200 if the data source was successfully created. Otherwise, an exception is raised.

    Args:
        name(Text): A unique name for the data source. A data source name can't be changed without deleting and
            recreating the data source.
        index_id(Text): The identifier of the index that should be associated with this data source.
        type_(Text): The type of repository that contains the data source.
        configuration(Dict, optional): The connector configuration information that is required to access the repository. You can't
            specify the Configuration parameter when the Type parameter is set to CUSTOM. If you do, you
            receive a ValidationException exception. The Configuration parameter is required for all other
            data sources. Defaults to None.
        description(Text, optional): A description for the data source. Defaults to None.
        schedule(Text, optional): Sets the frequency that Amazon Kendra will check the documents in your repository and update the
            index. If you don't set a schedule Amazon Kendra will not periodically update the index. You can
            call the StartDataSourceSyncJob operation to update the index. You can't specify the Schedule
            parameter when the Type parameter is set to CUSTOM. If you do, you receive a ValidationException
            exception. Defaults to None.
        role_arn(Text, optional): The Amazon Resource Name (ARN) of a role with permission to access the data source. For more
            information, see IAM Roles for Amazon Kendra. You can't specify the RoleArn parameter when the
            Type parameter is set to CUSTOM. If you do, you receive a ValidationException exception. The
            RoleArn parameter is required for all other data sources. Defaults to None.
        tags(List, optional): A list of key-value pairs that identify the data source. You can use the tags to identify and
            organize your resources and to control access to resources. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.kendra.create_data_source(
                ctx,
                
                ClientToken=name,
                **{"Name": name, "IndexId": index_id, "Type": type_, "Configuration": configuration, "Description": description, "Schedule": schedule, "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_data_source(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 Amazon Kendra data source. An exception is not thrown if the data source is already being deleted.
    While the data source is being deleted, the Status field returned by a call to the DescribeDataSource operation
    is set to DELETING. For more information, see Deleting Data Sources.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

