from typing import Optional, List
from pydantic import BaseModel
from datetime import datetime


class DatabaseOut(BaseModel):
    id: int
    source_id: int
    name: str
    charset: Optional[str] = None
    table_count: int = 0
    created_at: datetime

    class Config:
        from_attributes = True


class DataTableOut(BaseModel):
    id: int
    database_id: int
    name: str
    comment: Optional[str] = None
    row_count: int = 0
    column_count: int = 0
    created_at: datetime

    class Config:
        from_attributes = True


class DataColumnOut(BaseModel):
    id: int
    table_id: int
    name: str
    data_type: Optional[str] = None
    length: Optional[int] = None
    comment: Optional[str] = None
    is_nullable: bool = True
    sample_data: Optional[str] = None
    created_at: datetime

    class Config:
        from_attributes = True


class MetadataTreeNode(BaseModel):
    id: int
    name: str
    type: str  # source, database, table, column
    children: Optional[List["MetadataTreeNode"]] = None
    meta: Optional[dict] = None
