from sqlalchemy import String, Text, Boolean, func, text from sqlalchemy.orm import Mapped, mapped_column, relationship from datetime import datetime from typing import Optional, List from app.database import Base class Location(Base): __tablename__ = "locations" id: Mapped[int] = mapped_column(primary_key=True, index=True) name: Mapped[str] = mapped_column(String(255), nullable=False) address: Mapped[str] = mapped_column(Text, nullable=False) category: Mapped[str] = mapped_column(String(100), default="other") is_frequent: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, server_default=text('false')) contact_number: Mapped[Optional[str]] = mapped_column(String(50), nullable=True) email: Mapped[Optional[str]] = mapped_column(String(255), nullable=True) notes: Mapped[Optional[str]] = mapped_column(Text, nullable=True) created_at: Mapped[datetime] = mapped_column(default=func.now()) updated_at: Mapped[datetime] = mapped_column(default=func.now(), onupdate=func.now()) # Relationships events: Mapped[List["CalendarEvent"]] = relationship(back_populates="location")