from cpm_assessment import db

class AssessmentRequest(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    consultant_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    assessment_id = db.Column(db.Integer, db.ForeignKey('assessment.id'), nullable=False)
    requested_quantity = db.Column(db.Integer, nullable=False)
    total_cost = db.Column(db.Float, nullable=False)
    payment_slip_url = db.Column(db.String(200), nullable=True) # Path to uploaded payment slip
    status = db.Column(db.String(20), nullable=False, default='pending') # pending, approved, rejected
    assigned_count = db.Column(db.Integer, nullable=False, default=0) # How many assessments assigned from this request
    request_date = db.Column(db.DateTime, nullable=False, default=db.func.current_timestamp())
    admin_notes = db.Column(db.Text, nullable=True)

    consultant = db.relationship('User', back_populates='assessment_requests') # Use back_populates

    def __repr__(self):
        return f"AssessmentRequest(Consultant: {self.consultant_id}, Assessment: {self.assessment_id}, Quantity: {self.requested_quantity}, Status: {self.status})"
