import { Schema, model } from 'mongoose';
import {
  ILeadScoreConfigDoc,
  ILeadScoreConfigModel,
} from './leadScore.interface';
import { paginate, toJSON } from '@/shared/utils/plugins';

const activityPointsSchema = new Schema(
  {
    activityId: { type: String, required: true },
    points: { type: Number, required: true, default: 0 },
  },
  { _id: false },
);

const leadScoreConfigSchema = new Schema<ILeadScoreConfigDoc>(
  {
    companyId: {
      type: Schema.Types.ObjectId,
      ref: 'Company',
      unique: true,
    },
    activityPoints: [activityPointsSchema],
    zeroScoreIfLeadLost: { type: Boolean, default: false },
    fullScoreIfLeadWon: { type: Boolean, default: false },
    createdBy: { type: Schema.Types.ObjectId, ref: 'User' },
    updatedBy: { type: Schema.Types.ObjectId, ref: 'User' },
  },
  { timestamps: true },
);

leadScoreConfigSchema.plugin(toJSON);
leadScoreConfigSchema.plugin(paginate);



export const LeadScoreConfig = model<
  ILeadScoreConfigDoc,
  ILeadScoreConfigModel
>('LeadScoreConfig', leadScoreConfigSchema);
