import mongoose, { Document, Schema, Types } from 'mongoose';

export interface ISurvey extends Document {
    patientId: Types.ObjectId;
    appointmentId?: Types.ObjectId;
    rating: number; // 1-5
    feedback?: string;
    createdAt: Date;
}

const surveySchema = new Schema<ISurvey>({
    patientId: {
        type: Schema.Types.ObjectId,
        ref: 'Patient',
        required: true
    },
    appointmentId: {
        type: Schema.Types.ObjectId,
        ref: 'Appointment'
    },
    rating: {
        type: Number,
        required: true,
        min: 1,
        max: 5
    },
    feedback: {
        type: String,
        trim: true
    },
    createdAt: {
        type: Date,
        default: Date.now
    }
});

export default mongoose.model<ISurvey>('Survey', surveySchema);
