import { Schema, Types } from 'mongoose';
import { LeadBuyingPreference } from '@/shared/constants/enum.constant';

export const BuyLeadSchema = new Schema({
  buyingPreference: {
    type: String,
    enum: Object.values(LeadBuyingPreference),
    default: LeadBuyingPreference.OPEN_TO_SUGGESTION,
  },
  unit: { type: Types.ObjectId, ref: 'Unit' },
  loanRequired: Boolean,
  loanStage: String,
  purpose: { type: Types.ObjectId, ref: 'PropertyUsage' },
  project: { type: Types.ObjectId, ref: 'Project' },
  subCategoryId: { type: Types.ObjectId, ref: 'SubCategory' },
  preferredState: { type: Types.ObjectId, ref: 'State' },
  preferredCity: { type: Types.ObjectId, ref: 'City' },
  preferredLocalities: [{ type: Types.ObjectId, ref: 'Area' }],
  budget: {
    type: Schema.Types.Decimal128,
    get: (v) => (v ? parseFloat(v.toString()) : v),
  },
  propertyCategory: String,
  sourceProjectId: String,
  sourceProjectName: String,
  sourceLocality: String,
  sourceUrl: String,
});
