from datetime import datetime
from sqlalchemy import Column, Integer, String, Text, DateTime
from backend.database.connection import Base


class Idea(Base):
    __tablename__ = "ideas"

    id = Column(Integer, primary_key=True, index=True)
    title = Column(String(500), nullable=False)
    url = Column(String(2000), default="")
    platform = Column(String(50), default="")
    thumbnail_url = Column(String(2000), default="")
    notes = Column(Text, default="")
    status = Column(String(50), default="idea")  # idea, script, production, published
    video_id = Column(Integer, nullable=True)
    created_at = Column(DateTime, default=datetime.utcnow)
    updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)

    def to_dict(self):
        return {
            "id": self.id,
            "title": self.title,
            "url": self.url,
            "platform": self.platform,
            "thumbnail_url": self.thumbnail_url,
            "notes": self.notes,
            "status": self.status,
            "video_id": self.video_id,
            "created_at": self.created_at.isoformat() if self.created_at else None,
            "updated_at": self.updated_at.isoformat() if self.updated_at else None,
        }
