<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\StokAkhir;
use App\Models\PriceSetting;

class ProductSeeder extends Seeder
{
    public function run(): void
    {
        // 1. Seed stok_akhir (Produk)
        $products = [
            [
                'id_produk' => 'LPG3',
                'nama_produk' => 'Gas LPG 3 Kg',
                'jenis_barang' => '3 Kg',
                'stok_isi' => 100,
                'stok_kosong' => 50,
                'total_aset' => 150,
            ],
            [
                'id_produk' => 'LPG55',
                'nama_produk' => 'Bright Gas 5.5 Kg',
                'jenis_barang' => '5.5 Kg',
                'stok_isi' => 50,
                'stok_kosong' => 20,
                'total_aset' => 70,
            ],
            [
                'id_produk' => 'LPG12',
                'nama_produk' => 'Bright Gas 12 Kg',
                'jenis_barang' => '12 Kg',
                'stok_isi' => 30,
                'stok_kosong' => 15,
                'total_aset' => 45,
            ],
        ];

        foreach ($products as $product) {
            StokAkhir::updateOrCreate(['id_produk' => $product['id_produk']], $product);
        }

        // 2. Seed price_settings (Harga)
        // Primary key id_price_setting disesuaikan dengan id_produk untuk relasi
        $prices = [
            [
                'id_price_setting' => 'LPG3',
                'name' => 'Gas LPG 3 Kg',
                'price' => 18000,
            ],
            [
                'id_price_setting' => 'LPG55',
                'name' => 'Bright Gas 5.5 Kg',
                'price' => 95000,
            ],
            [
                'id_price_setting' => 'LPG12',
                'name' => 'Bright Gas 12 Kg',
                'price' => 190000,
            ],
        ];

        foreach ($prices as $price) {
            PriceSetting::updateOrCreate(['id_price_setting' => $price['id_price_setting']], $price);
        }
    }
}
