# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/classes/50_DomoDatacenter.ipynb.

# %% auto 0
__all__ = ['DomoEntity', 'DomoDatacenter']

# %% ../../nbs/classes/50_DomoDatacenter.ipynb 3
import asyncio
import importlib
from dataclasses import dataclass, field
from enum import Enum

import httpx

from fastcore.basics import patch_to

import domolibrary.client.DomoAuth as dmda
import domolibrary.classes.DomoDataset as dmds

import domolibrary.routes.account as account_routes
import domolibrary.routes.datacenter as datacenter_routes

# %% ../../nbs/classes/50_DomoDatacenter.ipynb 4
class DomoEntity(Enum):
    "enumerates the entities that can be passed to the datacenter Search API"
    
    DATASET = "DATA_SOURCE" #dataset
    DATAFLOW = "DATAFLOW" #  dataflow
    PAGE = "PAGE" # page
    CARD = "CARD" # card
    ACCOUNT = "account" #account type


# %% ../../nbs/classes/50_DomoDatacenter.ipynb 5
class DomoDatacenter:
    "class for quering entities in the datacenter"
    auth: dmda.DomoAuth = None

    def __init__(self, auth):
        self.auth = auth

# %% ../../nbs/classes/50_DomoDatacenter.ipynb 6
@patch_to(DomoDatacenter, cls_method=True)
def generate_search_datacenter_body(
    cls,
    entity_name : str = None, # entity to search for, uses fuzzy logic
    entity_ls: list[str] = list[DomoEntity], # list of entity types to search
    filter_ls: [dict] = None, # filter parameters
    combineResults: bool = False, # facet / split results
    count: int = 100,
    offset: int = 0,
):
    body = {"query": "*" }
    if DomoEntity.ACCOUNT in entity_ls:
        body.update({
            "entityList": [[DomoEntity.ACCOUNT.value]],
        })

        if entity_name:
            body.update({"query": f"*{entity_name}*"})
    else:
        body.update({
            "entities": [entity.value for entity in entity_ls]
        })

        if entity_name:
            body.update({field: "name_sort", filterType: "wildcard", query: f"*{entity_name}*"})

    body.update({
        "count": count, "offset": offset,
        "filters": filter_ls or [],
        "combineResults": combineResults,
        
    })

    return body

