import { Types } from 'mongoose';

import { LeadStage } from '@/modules/master/leadStage/leadStage.model';

export const seedLeadStage = async ({
  superAdminId,
}: {
  superAdminId: string | Types.ObjectId;
}) => {
  const leadStages = [
    {
      name: 'New Lead',
      position: 1,
      description:
        'A fresh lead has just entered the system—yet to be contacted.',
      color: '#4A90E2',
    },
    {
      name: 'Lead Won',
      position: 2,
      description: 'Deal closed—lead converted into a customer.',
      color: '#2ECC71',
    },
    {
      name: 'Lead Lost',
      position: 3,
      description: 'Lead dropped—marked lost with reason for future insights.',
      color: '#E74C3C',
    },
  ];

  await Promise.all(
    leadStages.map((stage) =>
      LeadStage.updateOne(
        { stageName: stage.name },
        {
          $set: {
            ...stage,
            isDefault: true,
            isProtected: true,
            createdBy: superAdminId,
            updatedBy: superAdminId,
          },
        },
        { upsert: true },
      ),
    ),
  );
  return;
};
