<?php

declare(strict_types=1);

namespace Database\Seeders;

use PDO;

final class LeadPipelineSeeder implements SeederInterface
{
    public function run(PDO $pdo): void
    {
        $sources = [
            ['name' => 'Website Form', 'slug' => 'website_form', 'sort_order' => 1],
            ['name' => 'AI Voice Agent', 'slug' => 'ai_voice_agent', 'sort_order' => 2],
            ['name' => 'Referral', 'slug' => 'referral', 'sort_order' => 3],
            ['name' => 'Other', 'slug' => 'other', 'sort_order' => 4],
        ];

        $sourceStmt = $pdo->prepare(
            'INSERT INTO lead_sources (name, slug, is_active, sort_order) VALUES (:name, :slug, 1, :sort_order)
             ON DUPLICATE KEY UPDATE name = VALUES(name), sort_order = VALUES(sort_order)'
        );
        foreach ($sources as $source) {
            $sourceStmt->execute($source);
        }

        $stages = [
            ['name' => 'New', 'slug' => 'new', 'color_hex' => '#98A2B3', 'is_won' => 0, 'is_lost' => 0, 'sort_order' => 1],
            ['name' => 'Contacted', 'slug' => 'contacted', 'color_hex' => '#B7791F', 'is_won' => 0, 'is_lost' => 0, 'sort_order' => 2],
            ['name' => 'Quoted', 'slug' => 'quoted', 'color_hex' => '#4274B9', 'is_won' => 0, 'is_lost' => 0, 'sort_order' => 3],
            ['name' => 'Won', 'slug' => 'won', 'color_hex' => '#12805C', 'is_won' => 1, 'is_lost' => 0, 'sort_order' => 4],
            ['name' => 'Lost', 'slug' => 'lost', 'color_hex' => '#D2242A', 'is_won' => 0, 'is_lost' => 1, 'sort_order' => 5],
        ];

        $stageStmt = $pdo->prepare(
            'INSERT INTO lead_stages (name, slug, color_hex, is_won, is_lost, sort_order, is_active)
             VALUES (:name, :slug, :color_hex, :is_won, :is_lost, :sort_order, 1)
             ON DUPLICATE KEY UPDATE name = VALUES(name), color_hex = VALUES(color_hex), sort_order = VALUES(sort_order)'
        );
        foreach ($stages as $stage) {
            $stageStmt->execute($stage);
        }

        echo '  seeded ' . count($sources) . ' lead sources and ' . count($stages) . " pipeline stages\n";
    }
}
