<?php

namespace Database\Seeders;

use App\Models\Order;
use App\Models\OrderItem;
use App\Models\ProductVariant;
use Illuminate\Database\Seeder;

class OrderItemSeeder extends Seeder
{
    public function run(): void
    {
        $order = Order::query()->first();
        $variant = ProductVariant::query()->first();

        if ($order === null || $variant === null) {
            OrderItem::factory()->count(3)->create();

            return;
        }

        OrderItem::factory()
            ->count(2)
            ->create([
                'order_id' => $order->id,
                'product_variant_id' => $variant->id,
            ]);
    }
}
