<?php

namespace Database\Seeders;

use App\Models\Purchase;
use App\Models\PurchaseItem;
use App\Models\RawMaterialPrice;
use Illuminate\Database\Seeder;

class PurchaseItemSeeder extends Seeder
{
    public function run(): void
    {
        $purchase = Purchase::query()->first();
        $rawMaterialPrice = RawMaterialPrice::query()->first();

        if ($purchase === null || $rawMaterialPrice === null) {
            PurchaseItem::factory()->count(3)->create();

            return;
        }

        PurchaseItem::factory()
            ->count(3)
            ->create([
                'purchase_id' => $purchase->id,
                'raw_material_price_id' => $rawMaterialPrice->id,
            ]);
    }
}
