from sqlalchemy import Column, String, Text, Integer, Boolean, DateTime, ForeignKey
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.sql import func
import uuid

from app.core.database import Base

class MotivationalMessage(Base):
    __tablename__ = "motivational_messages"
    
    id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    message_type = Column(String(50), nullable=False)
    trigger_condition = Column(String(100), nullable=False)
    message_text = Column(Text, nullable=False)
    icon = Column(String(10))
    priority = Column(Integer, default=0)
    is_active = Column(Boolean, default=True)
    created_at = Column(DateTime(timezone=True), server_default=func.now())


class UserMessageLog(Base):
    __tablename__ = "user_messages_log"
    
    id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    user_id = Column(UUID(as_uuid=True), ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
    message_id = Column(UUID(as_uuid=True), ForeignKey("motivational_messages.id", ondelete="SET NULL"))
    message_text = Column(Text, nullable=False)
    message_type = Column(String(50))
    shown_at = Column(DateTime(timezone=True), server_default=func.now())
    was_clicked = Column(Boolean, default=False)
    clicked_at = Column(DateTime(timezone=True))
