from cpm_assessment import db
from datetime import datetime

class ClientAssessment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    client_id = db.Column(db.Integer, db.ForeignKey('client.id'), nullable=False)
    assessment_id = db.Column(db.Integer, db.ForeignKey('assessment.id'), nullable=False)
    score = db.Column(db.String(50), nullable=True)
    completed_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    feedback = db.Column(db.Text, nullable=True)


    client = db.relationship('Client', backref=db.backref('client_assessments', lazy=True))
    assessment = db.relationship('Assessment', backref=db.backref('assessment_clients', lazy=True))

    def __repr__(self):
        return f"ClientAssessment(Client: '{self.client.name}', Assessment: '{self.assessment.name}', Score: {self.score})"