from config import db
from datetime import datetime

class HomeSlider(db.Model):
    __tablename__ = 'home_sliders'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(255), nullable=False)
    description = db.Column(db.Text)
    image_url = db.Column(db.String(1000), nullable=False)
    link_type = db.Column(db.Enum('course', 'institute', 'video', 'external', 'internal'), default='internal')
    link_value = db.Column(db.String(500))
    display_order = db.Column(db.Integer, default=0)
    is_active = db.Column(db.Boolean, default=True)
    start_date = db.Column(db.DateTime)
    end_date = db.Column(db.DateTime)
    button_text = db.Column(db.String(100), default='Learn More')
    background_color = db.Column(db.String(20), default='#6366f1')
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)

    def to_dict(self):
        return {
            'id': self.id,
            'title': self.title,
            'description': self.description,
            'image_url': self.image_url,
            'link_type': self.link_type,
            'link_value': self.link_value,
            'display_order': self.display_order,
            'is_active': self.is_active,
            'start_date': self.start_date.isoformat() if self.start_date else None,
            'end_date': self.end_date.isoformat() if self.end_date else None,
            'button_text': self.button_text,
            'background_color': self.background_color,
            'created_at': self.created_at.isoformat() if self.created_at else None
        }
