<?php

namespace Database\Seeders;

use App\Models\Product;
use App\Models\InventoryBatch;
use Illuminate\Database\Seeder;

class ConvertExistingStockToBatches extends Seeder
{
    public function run()
    {
        $products = Product::where('stock', '>', 0)->get();
        
        foreach ($products as $product) {
            if ($product->stock > 0) {
                InventoryBatch::create([
                    'product_id' => $product->id,
                    'purchase_id' => null,
                    'batch_no' => 'INITIAL-BATCH-' . $product->id . '-' . time(),
                    'purchase_price' => $product->purchase_price,
                    'quantity' => $product->stock,
                    'remaining_quantity' => $product->stock,
                    'purchase_date' => now()
                ]);
            }
        }
    }
}