"""
Table component schemas.

Mirrors lightwave-ui/src/components/application/table/.
"""

from typing import Any, Literal

from pydantic import BaseModel, ConfigDict, Field


class TableColumn(BaseModel):
    """
    Table column definition.

    Matches TypeScript TableColumn interface.
    """

    key: str = Field(..., description="Column key/accessor")
    header: str = Field(..., description="Column header text")
    width: str | None = Field(None, description="Column width (CSS)")
    align: Literal["left", "center", "right"] | None = Field(None, description="Cell alignment")
    sortable: bool = Field(False, description="Column is sortable")
    render_type: str | None = Field(
        None,
        serialization_alias="renderType",
        description="Special render type (e.g., 'badge', 'avatar', 'date')",
    )

    model_config = ConfigDict(
        populate_by_name=True,
        extra="forbid",
    )


class TableProps(BaseModel):
    """
    Table component props.

    Matches TypeScript TableProps.
    """

    # Columns
    columns: list[TableColumn] = Field(..., description="Column definitions")

    # Data
    data: list[dict[str, Any]] = Field(default_factory=list, description="Table row data")

    # Selection
    selectable: bool = Field(False, description="Enable row selection")
    selected_keys: list[str] | None = Field(None, serialization_alias="selectedKeys", description="Selected row keys")

    # Sorting
    sort_column: str | None = Field(None, serialization_alias="sortColumn", description="Current sort column")
    sort_direction: Literal["asc", "desc"] | None = Field(
        None, serialization_alias="sortDirection", description="Sort direction"
    )

    # Pagination
    paginated: bool = Field(False, description="Enable pagination")
    page_size: int = Field(10, serialization_alias="pageSize", description="Rows per page")
    current_page: int = Field(1, serialization_alias="currentPage", description="Current page")
    total_rows: int | None = Field(None, serialization_alias="totalRows", description="Total row count")

    # Loading
    is_loading: bool = Field(False, serialization_alias="isLoading", description="Loading state")

    # Empty state
    empty_message: str | None = Field(None, serialization_alias="emptyMessage", description="Empty state message")

    model_config = ConfigDict(
        populate_by_name=True,
        extra="forbid",
    )


__all__ = [
    "TableColumn",
    "TableProps",
]
