"""Note models for AI-generated educational notes.""" from datetime import datetime from uuid import UUID, uuid4 from sqlalchemy import Column from sqlalchemy.dialects.postgresql import JSONB from sqlmodel import Field, SQLModel class NoteBase(SQLModel): """Base note model with shared fields.""" title: str = Field(max_length=255) content: str # Markdown formatted topic: str = Field(max_length=255, index=True) chapter: str | None = Field(default=None, max_length=255) book_reference: str | None = Field(default=None, max_length=500) # Configuration difficulty_level: str = Field( default="college", max_length=50, description="Education level: primary, high_school, college, undergrad, postgrad", ) # Customization options stored as JSON customization: dict = Field( default_factory=dict, sa_column=Column(JSONB), description="Customization settings (tone, depth, examples, etc.)", ) # Metadata word_count: int = Field(default=0, ge=0) has_diagrams: bool = Field(default=False) diagram_codes: list[str] = Field( default_factory=list, sa_column=Column(JSONB) ) view_count: int = Field(default=0, ge=0, description="Number of times note has been viewed") # Status is_ai_generated: bool = Field(default=True) is_edited: bool = Field(default=False) version: int = Field(default=1, ge=1) class Note(NoteBase, table=True): """Note table model.""" __tablename__ = "notes" id: UUID = Field(default_factory=uuid4, primary_key=True) user_id: str = Field(index=True) # String to support better-auth user IDs # Links to concepts and sessions concept_id: UUID | None = Field(default=None) session_id: UUID | None = Field(default=None) # Timestamps created_at: datetime = Field(default_factory=datetime.utcnow) updated_at: datetime = Field(default_factory=datetime.utcnow) last_viewed_at: datetime | None = None class NoteCreate(SQLModel): """Request model for creating a note.""" user_id: str # String to support better-auth user IDs topic: str chapter: str | None = None book_reference: str | None = None difficulty_level: str = "college" customization: dict = Field(default_factory=dict) session_id: str | None = None class NoteUpdate(SQLModel): """Request model for updating a note.""" title: str | None = None content: str | None = None chapter: str | None = None book_reference: str | None = None customization: dict | None = None is_edited: bool = True class NoteRead(NoteBase): """Response model for reading a note.""" id: UUID user_id: str # String to support better-auth user IDs concept_id: UUID | None session_id: str | None created_at: datetime updated_at: datetime last_viewed_at: datetime | None view_count: int class NoteTemplateBase(SQLModel): """Base note template model.""" name: str = Field(max_length=100) description: str | None = Field(default=None, max_length=500) difficulty_level: str = Field(max_length=50) customization: dict = Field(default_factory=dict, sa_column=Column(JSONB)) is_default: bool = Field(default=False) class NoteTemplate(NoteTemplateBase, table=True): """Note template table model.""" __tablename__ = "note_templates" id: UUID = Field(default_factory=uuid4, primary_key=True) user_id: str = Field(index=True) # String to support better-auth user IDs usage_count: int = Field(default=0, ge=0) created_at: datetime = Field(default_factory=datetime.utcnow) class NoteTemplateCreate(SQLModel): """Request model for creating a note template.""" user_id: str # String to support better-auth user IDs name: str description: str | None = None difficulty_level: str customization: dict class NoteTemplateRead(NoteTemplateBase): """Response model for reading a note template.""" id: UUID user_id: str # String to support better-auth user IDs usage_count: int created_at: datetime __all__ = [ "Note", "NoteCreate", "NoteUpdate", "NoteRead", "NoteTemplate", "NoteTemplateCreate", "NoteTemplateRead", ]