from datetime import datetime
from flask_sqlalchemy import SQLAlchemy
from config import db
from sqlalchemy import Computed

class Questions(db.Model):
    __tablename__ = 'Questions'
    question_id = db.Column(db.Integer, primary_key=True)
    topic_id = db.Column(db.Integer, db.ForeignKey('topics.id', ondelete='CASCADE'), nullable=False)
    question_text = db.Column(db.Text)
    correct_answer = db.Column(db.String(255))
    
    # Relationship to the topic
    topic = db.relationship('Topic', back_populates='questions')

    # Relationship to options
    options = db.relationship('Options', back_populates='question')

class Options(db.Model):
    __tablename__ = 'Options'
    option_id = db.Column(db.Integer, primary_key=True)
    question_id = db.Column(db.Integer, db.ForeignKey('Questions.question_id'))
    option_text = db.Column(db.String(500))
    is_correct = db.Column(db.Boolean, default=False)

    # Relationship to the question
    question = db.relationship('Questions', back_populates='options')
