from typing import Optional, Union

from pydantic import Field
from pydantic import BaseModel as PydanticBaseModel
from tesseract_olap.query import JoinIntent


class BaseModel(PydanticBaseModel):
    class Config:
        arbitrary_types_allowed = True


class JoinOnColumns(BaseModel):
    """Specifies the columns to be used in a merge operation, when their names are different."""

    left_on: Union[str, list[str]]
    right_on: Union[str, list[str]]


class PaginationIntent(BaseModel):
    limit: int = 0
    offset: int = 0


class QueryRequest(BaseModel):
    url: str
    data: Optional[str] = None
    headers: Optional[str] = None


class MergeParams(BaseModel):
    query_left : QueryRequest
    query_right: QueryRequest
    pagination: PaginationIntent = Field(default_factory=PaginationIntent)
    join: JoinIntent


class CubeRequest(BaseModel):
    cube_name: list[str]
    locale: str
    show_all: Optional[bool] = False


class ColumnsRequest(BaseModel):
    columns: list[str]


class FileParams(BaseModel):
    filename: str
    annotations: dict

    def get_annotations(self):
        return self.annotations