<?php
require __DIR__ . '/../vendor/autoload.php';
$app = require __DIR__ . '/../bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();

use App\Models\Product;
use App\Models\ProductSize;

$standardSizes = ['S','M','L','XL','XXL'];
$addedTotal = 0;

foreach (Product::all() as $product) {
    $existing = $product->sizes()->pluck('size')->map(fn($s)=>strtoupper($s))->toArray();
    foreach ($standardSizes as $size) {
        if (!in_array($size, $existing)) {
            ProductSize::create([
                'product_id' => $product->id,
                'size' => $size,
                'stock' => 0,
            ]);
            $addedTotal++;
        }
    }
    $product->syncStock();
}

echo "Added product sizes: $addedTotal\n";
echo "Products: " . Product::count() . PHP_EOL;
echo "ProductSizes: " . ProductSize::count() . PHP_EOL;
