import { PrismaClient } from '@prisma/client';
import * as dotenv from 'dotenv';

dotenv.config();

const prisma = new PrismaClient();

async function main() {
  console.log('Seeding contract templates...');

  const templates = [
    {
      id: 'south-africa-roofing',
      name: 'South Africa Roofing Contract',
      description: 'Standard roofing contract for South Africa with CPA compliance',
      region: 'SOUTH_AFRICA' as const,
      serviceType: 'roofing',
    },
    {
      id: 'usa-roofing',
      name: 'USA Roofing Contract',
      description: 'Standard roofing contract for United States',
      region: 'USA' as const,
      serviceType: 'roofing',
    },
    {
      id: 'uk-roofing',
      name: 'UK Roofing Contract',
      description: 'Standard roofing contract for United Kingdom',
      region: 'UNITED_KINGDOM' as const,
      serviceType: 'roofing',
    },
    {
      id: 'australia-roofing',
      name: 'Australia Roofing Contract',
      description: 'Standard roofing contract for Australia',
      region: 'AUSTRALIA' as const,
      serviceType: 'roofing',
    },
  ];

  for (const template of templates) {
    await prisma.contractTemplate.upsert({
      where: { id: template.id },
      update: {},
      create: {
        ...template,
        version: '1.0',
        isActive: true,
        isDefault: true,
        legalReview: true,
        reviewedAt: new Date(),
        jurisdictions: [template.region],
        variables: {
          customerName: '',
          customerAddress: '',
          contractorName: '',
          contractorLicense: '',
          projectAddress: '',
          totalAmount: 0,
          startDate: '',
          completionDate: '',
        },
        templateContent: 'Standard contract template content will be populated by legal team.',
      },
    });
  }

  console.log('Contract templates seeded successfully!');
}

main()
  .catch((e) => {
    console.error(e);
    process.exit(1);
  })
  .finally(async () => {
    await prisma.$disconnect();
  });
