import mongoose, { Document, Schema } from 'mongoose' export interface IDeveloperRequest extends Document { userId: mongoose.Types.ObjectId planId: string planName: string planPrice: number requirements: string contactInfo: { name: string email: string phone?: string } status: 'pending' | 'approved' | 'in_progress' | 'completed' | 'cancelled' paymentStatus: 'pending' | 'paid' | 'failed' transactionId?: mongoose.Types.ObjectId assignedDeveloper?: { name: string email: string skills: string[] } estimatedStartDate?: Date estimatedCompletionDate?: Date actualStartDate?: Date actualCompletionDate?: Date notes?: string createdAt: Date updatedAt: Date } const DeveloperRequestSchema = new Schema( { userId: { type: Schema.Types.ObjectId, ref: 'User', required: true, }, planId: { type: String, required: true, enum: ['hourly', 'daily', 'monthly'], }, planName: { type: String, required: true, }, planPrice: { type: Number, required: true, }, requirements: { type: String, required: true, minlength: 10, maxlength: 5000, }, contactInfo: { name: { type: String, required: true, trim: true, }, email: { type: String, required: true, lowercase: true, trim: true, }, phone: { type: String, trim: true, }, }, status: { type: String, enum: ['pending', 'approved', 'in_progress', 'completed', 'cancelled'], default: 'pending', }, paymentStatus: { type: String, enum: ['pending', 'paid', 'failed'], default: 'pending', }, transactionId: { type: Schema.Types.ObjectId, ref: 'Transaction', }, assignedDeveloper: { name: String, email: String, skills: [String], }, estimatedStartDate: Date, estimatedCompletionDate: Date, actualStartDate: Date, actualCompletionDate: Date, notes: { type: String, maxlength: 2000, }, }, { timestamps: true, } ) // Indexes for better query performance DeveloperRequestSchema.index({ userId: 1, createdAt: -1 }) DeveloperRequestSchema.index({ status: 1 }) DeveloperRequestSchema.index({ paymentStatus: 1 }) export const DeveloperRequest = mongoose.models.DeveloperRequest || mongoose.model('DeveloperRequest', DeveloperRequestSchema)