from sqlalchemy import String, Text, ForeignKey, DateTime, Boolean
from sqlalchemy.dialects.mysql import CHAR
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.core.models import BaseModel
from app.core.models.user import User

class Note(BaseModel):
    """
    Represents internal sticky notes or personal memos.
    
    Notes are used for quick information storage and can be color-coded 
    for visual categorization. Access is restricted to the owner.
    """
    __tablename__ = 'collab_note'

    title: Mapped[str | None] = mapped_column(String(100), nullable=True)
    content: Mapped[str] = mapped_column(Text, nullable=False)
    
    # UI color variant (e.g., 'warning', 'info', 'success')
    color: Mapped[str] = mapped_column(String(20), default='warning') 

    owner_id: Mapped[str] = mapped_column(CHAR(36), ForeignKey('user.id'), nullable=False)

    # Relationships
    owner = relationship('User')

    def __repr__(self):
        return f"<Note {self.title or self.id}>"

class Message(BaseModel):
    """
    Represents an internal system-to-system message (Direct Mail).
    
    Facilitates peer-to-peer communication between system users 
    within the AKSARA ecosystem.
    """
    __tablename__ = 'collab_message'

    sender_id: Mapped[str] = mapped_column(CHAR(36), ForeignKey('user.id'), nullable=False)
    recipient_id: Mapped[str] = mapped_column(CHAR(36), ForeignKey('user.id'), nullable=False)

    subject: Mapped[str] = mapped_column(String(150), nullable=False)
    body: Mapped[str] = mapped_column(Text, nullable=False)

    # Status tracking
    is_read: Mapped[bool] = mapped_column(Boolean, default=False)

    # Relationships
    sender = relationship('User', foreign_keys=[sender_id])
    recipient = relationship('User', foreign_keys=[recipient_id])

    def __repr__(self):
        return f"<Message {self.subject}>"
