from typing import Annotated, Literal

from pydantic import BaseModel, Discriminator


class ConfigParamsGetterMixin(BaseModel):
    def get_config_params(self) -> dict[str, any]:
        return self.model_dump(exclude={"type"}, exclude_none=True)


class FilesConfigBasic(ConfigParamsGetterMixin, BaseModel):
    type: Literal["basic"] = "basic"


class FilesConfigDir(ConfigParamsGetterMixin, BaseModel):
    type: Literal["dir"] = "dir"
    files_dir: str


class FilesConfigS3(ConfigParamsGetterMixin, BaseModel):
    type: Literal["s3"] = "s3"
    bucket: str
    region: str
    endpoint_url: str
    access_key: str
    secret_key: str


def config_discriminator(v: FilesConfigBasic | FilesConfigDir | FilesConfigS3) -> str:
    return v.type


FilesConfig = Annotated[
    FilesConfigBasic | FilesConfigDir | FilesConfigS3,
    Discriminator(config_discriminator),
]
