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

export interface IInquiry extends Document {
  firstName: string;
  lastName?: string;
  email: string;
  mobile: string;
  state?: mongoose.Types.ObjectId;
  orderNumber?: string;
  feedback?: string;
  createdAt: Date;
  updatedAt: Date;
}

const InquirySchema: Schema = new Schema(
  {
    firstName: {
      type: String,
      required: [true, 'First name is required'],
      trim: true,
      maxlength: [100, 'First name cannot exceed 100 characters']
    },
    lastName: {
      type: String,
      trim: true,
      maxlength: [100, 'Last name cannot exceed 100 characters']
    },
    email: {
      type: String,
      required: [true, 'Email is required'],
      trim: true,
      lowercase: true
    },
    mobile: {
      type: String,
      required: [true, 'Mobile number is required'],
      trim: true
    },
    state: {
      type: Schema.Types.ObjectId,
      ref: 'states'
    },
    orderNumber: {
      type: String,
      trim: true
    },
    feedback: {
      type: String,
      trim: true,
      maxlength: [2000, 'Feedback cannot exceed 2000 characters']
    }
  },
  { timestamps: true }
);

InquirySchema.index({ email: 1 });
InquirySchema.index({ mobile: 1 });

export default mongoose.models.Inquiry || mongoose.model<IInquiry>('Inquiry', InquirySchema);
