from pydantic import BaseModel, Field, field_validator


class ShelfRead(BaseModel):
    id: int
    title: str
    library_id: int | None = None
    total: int | None = None  # Number of books in the shelf


class ShelfCreate(BaseModel):
    title: str = Field(min_length=1)
    library_id: int | None = None
    book_ids: list[int] = []

    @field_validator("title", mode="before")
    @classmethod
    def strip_title(cls, v: str) -> str:
        return v.strip() if isinstance(v, str) else v
