from pydantic import BaseModel
from typing import List, Optional


# --- Request / Response schemas ---

class NoteCreate(BaseModel):
    """Create a new equipment note/log entry."""
    title: str
    content: str
    category: str = "general"  # general, maintenance, installation, issue, action_item, other
    device_id: Optional[str] = None  # Firestore doc ID of linked device
    user_id: Optional[str] = None  # Firestore doc ID of linked user
    status: str = ""  # "", "completed"


class NoteUpdate(BaseModel):
    """Update an existing note. Only provided fields are updated."""
    title: Optional[str] = None
    content: Optional[str] = None
    category: Optional[str] = None
    device_id: Optional[str] = None
    user_id: Optional[str] = None
    status: Optional[str] = None


class NoteInDB(BaseModel):
    """Note as stored in Firestore."""
    id: str
    title: str = ""
    content: str = ""
    category: str = "general"
    device_id: str = ""
    user_id: str = ""
    device_name: str = ""
    user_name: str = ""
    created_by: str = ""
    created_at: str = ""
    updated_at: str = ""
    status: str = ""


class NoteListResponse(BaseModel):
    notes: List[NoteInDB]
    total: int
