# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/routes/filesets.ipynb.

# %% auto 0
__all__ = ['create_filesets_index', 'get_fileset', 'get_fileset_files']

# %% ../../nbs/routes/filesets.ipynb 1
import domolibrary.client.get_data as gd
import domolibrary.client.DomoError as dmde
import domolibrary.client.DomoAuth as dmda
import httpx

# %% ../../nbs/routes/filesets.ipynb 5
@gd.route_function
def create_filesets_index(
    auth: dmda.DomoAuth,
    index_id,
    embedding_model: str = "domo.domo_ai.domo-embed-text-multilingual-v1:cohere",
):
    """Creates a new vectorDB index."""
    url = f"{auth.domo_instance}.domo.com/api/recall/v1/indexes"

    payload = {
        "indexId": index_id,
        "embeddingModel": embedding_model,
    }
    res = gd.get_data(url, method="POST", body=payload)
    
    if not res.is_success:
        raise dmde.DomoError(res.response)
    
    return res


# %% ../../nbs/routes/filesets.ipynb 7
@gd.route_function
async def get_fileset(
    auth: dmda.DomoAuth,
    fileset_id: str,
    debug_api: bool = False,
    debug_num_stacks_to_drop=1,
    parent_class: str = None,
    session: httpx.AsyncClient = None,
):
    url = f"https://{auth.domo_instance}.domo.com/api/files/v1/filesets/{fileset_id}"
    res = await gd.get_data(
        auth=auth,
        method="GET",
        url=url,
        debug_api=debug_api,
        num_stacks_to_drop=debug_num_stacks_to_drop,
        parent_class=parent_class,
        session=session,
    )

    if not res.is_success:
        raise dmde.RouteError(res=res, debug_api=debug_api)

    return res

# %% ../../nbs/routes/filesets.ipynb 10
@gd.route_function
async def get_fileset_files(
    auth: dmda.DomoAuth,
    domo_fileset_id: str,
    body: dict = None,
    debug_api: bool = False,
    debug_num_stacks_to_drop=1,
    parent_class: str = None,
    session: httpx.AsyncClient = None,
):
    url = f"https://{auth.domo_instance}.domo.com/api/files/v1/filesets/{domo_fileset_id}/files/search?directoryPath=&immediateChildren=true"

    if not body:
        # default body will pull all files within the given fileset_id
        body = {
            "fieldSort": [{"field": "created", "order": "DESC"}],
            "filters": [],
            "dateFilters": [],
        }

    res = await gd.get_data(
        auth=auth,
        method="POST",
        url=url,
        body=body,
        debug_api=debug_api,
        num_stacks_to_drop=debug_num_stacks_to_drop,
        parent_class=parent_class,
        session=session,
    )
    if not res.is_success:
        raise dmde.RouteError(res=res)

    return res
