from blueprints import db
from flask_restful import fields
from sqlalchemy import func
from sqlalchemy.sql.expression import text
from datetime import datetime

from sqlalchemy import ForeignKey
from sqlalchemy import Table, Column, Integer

from blueprints.mentee.model import Mentees
from blueprints.module.model import Modules

class ReviewsModule(db.Model):
    __tablename__ = "reviews_module"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    mentee_id = db.Column(db.Integer, db.ForeignKey(Mentees.id, ondelete="CASCADE"), nullable=False)
    module_id = db.Column(db.Integer, db.ForeignKey(Modules.id, ondelete="CASCADE"), nullable=False)
    content = db.Column(db.Text)
    score = db.Column(db.Integer)
    status = db.Column(db.Boolean)
    created_at = db.Column(db.DateTime(timezone=True), server_default=func.now())
    updated_at = db.Column(db.DateTime(timezone=True), onupdate=func.now())

    response_fields = {
        "id": fields.Integer,
        "mentee_id": fields.Integer,
        "module_id": fields.Integer,
        "content": fields.String,
        "score": fields.Integer,
        "status": fields.Boolean,
        "created_at": fields.DateTime,
        "update_at": fields.DateTime
    }

    def __init__ (self, mentee_id, module_id, content, score, status):
        self.mentee_id = mentee_id
        self.module_id = module_id
        self.content = content
        self.score = score
        self.status = status

    def __rpr__(self):
        return "<Users %r>" % self.id