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

export interface ILeads extends Document {
  name: string;
  phone_number: string;
  state:string;
  city:string;
  address:string;
}

const LeadsSchema: Schema = new Schema({
  name: {
    type: String,
    required: [true, 'Name is required'],
    trim: true,
    maxlength: [250, 'Name cannot exceed 250 characters']
  },
  phone_number: {
    type: String,
    required: [true, 'Phone number is required'],
   
    validate: {
        validator: function (v: string) {
        return /^[6-9]\d{9}$/.test(v);
        },
        message: 'Invalid Indian phone number'
    }
  },
  state:{
    type: mongoose.Schema.Types.ObjectId,
    ref:'states',

  },
   city:{
    type:String,
    maxlength: [500, 'Address cannot exceed 500 characters']
  },
  address: {
    type: String,
    trim: true,
    maxlength: [500, 'Address cannot exceed 500 characters']
  }
}, {
  timestamps: true
});



export default mongoose.models.Leads || mongoose.model<ILeads>('Leads', LeadsSchema);