const mongoose = require('mongoose');

const contactSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true,
    trim: true
  },
  email: {
    type: String,
    required: true,
    lowercase: true,
    trim: true
  },
  phone: {
    type: String,
    trim: true
  },
  company: {
    type: String,
    trim: true
  },
  subject: {
    type: String,
    required: true,
    trim: true
  },
  message: {
    type: String,
    required: true
  },
  serviceInterest: {
    type: String,
    enum: ['web-development', 'mobile-app', 'ui-ux-design', 'branding', 'consulting', 'other']
  },
  budget: {
    type: String,
    enum: ['under-1m', '1m-5m', '5m-10m', '10m-20m', '20m-50m', 'over-50m']
  },
  timeline: {
    type: String,
    enum: ['asap', '1-month', '1-3-months', '3-6-months', 'flexible']
  },
  status: {
    type: String,
    enum: ['new', 'in-progress', 'replied', 'closed'],
    default: 'new'
  },
  priority: {
    type: String,
    enum: ['low', 'medium', 'high', 'urgent'],
    default: 'medium'
  },
  source: {
    type: String,
    enum: ['website', 'telegram', 'email', 'phone', 'referral'],
    default: 'website'
  },
  isRead: {
    type: Boolean,
    default: false
  },
  adminNotes: {
    type: String
  },
  ipAddress: {
    type: String
  },
  userAgent: {
    type: String
  }
}, {
  timestamps: true
});

contactSchema.index({ status: 1, createdAt: -1 });
contactSchema.index({ isRead: 1, createdAt: -1 });
contactSchema.index({ email: 1 });

module.exports = mongoose.model('Contact', contactSchema);