<?php

namespace Database\Seeders;

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

class ProductSeeder extends Seeder
{
    public function run(): void
    {
        // Get the first user
        $user = User::first();

        if (!$user) {
            return;
        }

        // Create sample products
        $products = [
            [
                'product_code' => 'PROD-001',
                'name' => 'Laptop Computer',
                'purchase_price' => 40000.00,
                'sale_price' => 55000.00,
                'current_stock' => 10,
                'minimum_stock' => 2,
                'user_id' => $user->id,
            ],
            [
                'product_code' => 'PROD-002',
                'name' => 'Wireless Mouse',
                'purchase_price' => 500.00,
                'sale_price' => 899.00,
                'current_stock' => 50,
                'minimum_stock' => 5,
                'user_id' => $user->id,
            ],
            [
                'product_code' => 'PROD-003',
                'name' => 'USB-C Cable',
                'purchase_price' => 150.00,
                'sale_price' => 299.00,
                'current_stock' => 100,
                'minimum_stock' => 10,
                'user_id' => $user->id,
            ],
            [
                'product_code' => 'PROD-004',
                'name' => 'External Hard Drive',
                'purchase_price' => 3000.00,
                'sale_price' => 4499.00,
                'current_stock' => 15,
                'minimum_stock' => 3,
                'user_id' => $user->id,
            ],
            [
                'product_code' => 'PROD-005',
                'name' => 'Mechanical Keyboard',
                'purchase_price' => 2500.00,
                'sale_price' => 3999.00,
                'current_stock' => 20,
                'minimum_stock' => 3,
                'user_id' => $user->id,
            ],
        ];

        foreach ($products as $product) {
            Product::firstOrCreate(
                ['product_code' => $product['product_code']],
                $product
            );
        }
    }
}
