from __future__ import annotations

from typing import Any, List, Optional

from pydantic import BaseModel, Field


class FieldConfig(BaseModel):
    source_name: str
    default_value: str = "-"
    # If True, this field is handled as an array [x, y, z]
    is_list: bool = False
    # If present, this field is a nested object, not a primitive
    nested_schema: Optional["CompactSchema"] = None


class CompactSchema(BaseModel):
    name: str
    fields: List[FieldConfig]

    def get_field_names(self) -> List[str]:
        return [f.source_name for f in self.fields]


# Necessary for Pydantic to resolve the recursive reference
FieldConfig.model_rebuild()
