from sqlalchemy import Column, Integer, String, Boolean, DateTime, Text, ForeignKey
from sqlalchemy.orm import relationship
from datetime import datetime, timezone
from database import Base


def _utcnow():
    return datetime.now(timezone.utc)


class SiteNote(Base):
    __tablename__ = "site_notes"

    id = Column(Integer, primary_key=True, index=True)
    body = Column(Text, nullable=False)
    created_by_id = Column(Integer, ForeignKey("users.id"), nullable=False)
    created_at = Column(DateTime(timezone=True), default=_utcnow)
    updated_at = Column(DateTime(timezone=True), default=_utcnow, onupdate=_utcnow)
    is_pinned = Column(Boolean, default=False, nullable=False)

    created_by = relationship("User", foreign_keys=[created_by_id])


class SiteTodo(Base):
    __tablename__ = "site_todos"

    id = Column(Integer, primary_key=True, index=True)
    body = Column(Text, nullable=False)
    is_done = Column(Boolean, default=False, nullable=False)
    done_at = Column(DateTime(timezone=True), nullable=True)
    done_by_id = Column(Integer, ForeignKey("users.id"), nullable=True)
    created_by_id = Column(Integer, ForeignKey("users.id"), nullable=False)
    created_at = Column(DateTime(timezone=True), default=_utcnow)
    priority = Column(String, default="normal", nullable=False)  # "normal" | "high"

    created_by = relationship("User", foreign_keys=[created_by_id])
    done_by = relationship("User", foreign_keys=[done_by_id])
