from pathlib import Path
from typing import Annotated
from pydantic import BaseModel, Field, computed_field
from  advanced_alchemy.utils.text import slugify

class LibraryCreate(BaseModel):
    name: Annotated[str, Field(min_length=1)]
    root_path: str
    path_template: str | None = "{author}/{title}"
    description: str | None = None
    read_only: bool = False

    @computed_field
    @property
    def slug(self) -> str:
        return slugify(self.name)

class LibraryRead(BaseModel):
    id: int
    name: str
    root_path: str
    path_template: str
    description: str | None
    read_only: bool
    total: int | None = None


class LibraryUpdate(BaseModel):
    name: str | None
    root_path: str | None
    path_template: str | None
    description: str | None
    read_only: bool | None
