<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\Product;
use App\Models\Category;
use Illuminate\Support\Facades\DB;

class IceCreamContainerProductsSeeder extends Seeder
{
    public function run(): void
    {
        $this->command->info('');
        $this->command->info('🍦 Ice Cream Container Products Seeder');
        $this->command->info('═══════════════════════════════════════');
        $this->command->info('');

        DB::transaction(function () {
            $category = Category::firstOrCreate(
                ['name' => 'Ice Cream Containers'],
                [
                    'slug' => 'ice-cream-containers',
                    'description' => 'Pre-portioned ice cream serving sizes',
                    'is_active' => true,
                ]
            );

            $this->command->info("📁 Category: {$category->name}");
            $this->command->info('');
            $this->command->info('🍨 Creating container products...');
            $this->command->info('');

            $containers = [
                [
                    'name' => 'Small Cup Ice Cream',
                    'slug' => 'small-cup-ice-cream',
                    'description' => 'Perfect for a quick treat - Choose any 2 scoops',
                    'category_id' => $category->id,
                    'base_price' => 7.50,
                    'scoop_price' => 3.75,
                    'scoop_capacity' => 2,
                    'has_inner_options' => true,
                    'is_active' => true,
                    'metadata' => json_encode([
                        'container_type' => 'small_cup',
                        'sku' => 'ICE-CUP-SMALL-2',
                        'total_weight_grams' => 120,
                        'weight_per_scoop_grams' => 60,
                    ]),
                ],
                [
                    'name' => 'Medium Cup Ice Cream',
                    'slug' => 'medium-cup-ice-cream',
                    'description' => 'Most popular choice - Choose any 3 scoops',
                    'category_id' => $category->id,
                    'base_price' => 9.50,
                    'scoop_price' => 3.17,
                    'scoop_capacity' => 3,
                    'has_inner_options' => true,
                    'is_active' => true,
                    'metadata' => json_encode([
                        'container_type' => 'medium_cup',
                        'sku' => 'ICE-CUP-MEDIUM-3',
                        'total_weight_grams' => 170,
                        'weight_per_scoop_grams' => 56.67,
                    ]),
                ],
                [
                    'name' => 'Family Deal Ice Cream',
                    'slug' => 'family-deal-ice-cream',
                    'description' => 'Best value - Choose any 6 scoops',
                    'category_id' => $category->id,
                    'base_price' => 18.00,
                    'scoop_price' => 3.00,
                    'scoop_capacity' => 6,
                    'has_inner_options' => true,
                    'is_active' => true,
                    'metadata' => json_encode([
                        'container_type' => 'family_deal',
                        'sku' => 'ICE-DEAL-FAMILY-6',
                        'total_weight_grams' => 310,
                        'weight_per_scoop_grams' => 51.67,
                    ]),
                ],
            ];

            foreach ($containers as $data) {
                $product = Product::updateOrCreate(
                    ['slug' => $data['slug']],
                    $data
                );
                
                $this->command->info("✓ {$product->name} - \${$product->base_price} ({$product->scoop_capacity} scoops)");
            }

            $this->command->info('');
            $this->command->info('✅ Container products seeded!');
        });
    }
}
