<?php

namespace Database\Seeders;

use App\Models\ProductConfigOption;
use App\Models\ProductConfigOptionGroup;
use App\Models\ProductConfigOptionValue;
use Illuminate\Database\Seeder;

class ProductConfigOptionSeeder extends Seeder
{
    public function run(): void
    {
        // QA fixtures (PRC-532): 4 config opsiyonu + değerleri. Pricing PricingSeeder'da.
        ProductConfigOptionValue::query()->forceDelete();
        ProductConfigOption::query()->forceDelete();

        $group = ProductConfigOptionGroup::where('name', 'QA Yapılandırma')->firstOrFail();

        $options = [
            ['name' => 'RAM',       'type' => 'select',   'is_required' => false, 'values' => ['2 GB', '4 GB', '8 GB'], 'default' => '4 GB'], // PRC-789 — mağazada ön-seçili (anchor pricing)
            ['name' => 'Disk',      'type' => 'select',   'is_required' => false, 'values' => ['50 GB', '100 GB']],
            ['name' => 'Yedekleme', 'type' => 'select',   'is_required' => true,  'values' => ['Yok', 'Günlük', 'Haftalık']],
            ['name' => 'vCPU',      'type' => 'select',   'is_required' => true,  'values' => ['1 Çekirdek', '2 Çekirdek', '4 Çekirdek']],
        ];

        $order = 1;
        foreach ($options as $opt) {
            $option = ProductConfigOption::create([
                'group_id'    => $group->id,
                'name'        => $opt['name'],
                'description' => $opt['name'].' — QA opsiyonu',
                'type'        => $opt['type'],
                'values'      => $opt['values'],
                'order'       => $order++,
                'hidden'      => false,
                'is_required' => $opt['is_required'],
            ]);

            $valueOrder = 1;
            foreach ($opt['values'] as $value) {
                ProductConfigOptionValue::create([
                    'option_id'  => $option->id,
                    'value'      => $value,
                    'order'      => $valueOrder++,
                    'status'     => true,
                    'is_default' => isset($opt['default']) && $opt['default'] === $value, // PRC-789
                ]);
            }
        }
    }
}
