<?php

namespace Database\Seeders;

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

class ProductSeeder extends Seeder
{
    public function run(): void
    {
        $products = [
            // ── Produk 350ml (barcode panjang) ───────────────────────────
            [
                'sku'           => 'VBT-350',
                'barcode'       => '211182001000150',
                'name'          => 'VIBE BLACK TEA (350ml)',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 1115,
                'min_stock'     => 100,
                'buy_price'     => 5000,
                'sell_price'    => 7500,
            ],
            [
                'sku'           => 'VEL-350',
                'barcode'       => '21182001800152',
                'name'          => 'VIBE EXOTIC LYCHEE (350ml)',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 3191,
                'min_stock'     => 100,
                'buy_price'     => 5000,
                'sell_price'    => 7500,
            ],

            // ── Produk reguler VIBE ───────────────────────────────────────
            [
                'sku'           => 'VBT-REG',
                'barcode'       => '8997005490009',
                'name'          => 'VIBE BLACK TEA',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 12865,
                'min_stock'     => 200,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
            [
                'sku'           => 'VEL-REG',
                'barcode'       => '8997005490016',
                'name'          => 'VIBE EXOTIC LYCHEE',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 6915,
                'min_stock'     => 200,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
            [
                'sku'           => 'VSA-REG',
                'barcode'       => '8997005490023',
                'name'          => 'VIBE SAMBUCA',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 580,
                'min_stock'     => 50,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
            [
                'sku'           => 'VTS-REG',
                'barcode'       => '8997005490030',
                'name'          => 'VIBE TRIPLE SEC',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 1837,
                'min_stock'     => 100,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
            [
                'sku'           => 'VRC-REG',
                'barcode'       => '8997005490047',
                'name'          => 'VIBE RAW COFFE',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 1212,
                'min_stock'     => 100,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
            [
                'sku'           => 'VBC-REG',
                'barcode'       => '8997005490054',
                'name'          => 'VIBE BLUE CURACAO',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 1661,
                'min_stock'     => 100,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
            [
                'sku'           => 'VTC-REG',
                'barcode'       => '8997005490061',
                'name'          => 'VIBE TROPICAL COCONUT',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 3225,
                'min_stock'     => 100,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
            [
                'sku'           => 'VME-REG',
                'barcode'       => '8997005490078',
                'name'          => 'VIBE MELON',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 661,
                'min_stock'     => 50,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
            [
                'sku'           => 'VPE-REG',
                'barcode'       => '8997005490122',
                'name'          => 'VIBE PEACH',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 1838,
                'min_stock'     => 100,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
            [
                'sku'           => 'VPE-350',
                'barcode'       => '8997005490122 (350Ml)',
                'name'          => 'VIBE PEACH (350Ml)',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 3224,
                'min_stock'     => 100,
                'buy_price'     => 5000,
                'sell_price'    => 7500,
            ],
            [
                'sku'           => 'VOV-REG',
                'barcode'       => '8997005490177',
                'name'          => 'VIBE ORIGINAL VODKA',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 2369,
                'min_stock'     => 100,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
            [
                'sku'           => 'VTQ-REG',
                'barcode'       => '8997005490269',
                'name'          => 'VIBE TEQUILA',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 5624,
                'min_stock'     => 100,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
            [
                'sku'           => 'VWH-REG',
                'barcode'       => '8997005490276',
                'name'          => 'VIBE WHISKY',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 1561,
                'min_stock'     => 100,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
            [
                'sku'           => 'VVP-REG',
                'barcode'       => '8997005490283',
                'name'          => 'VIBE VODKA PREMIUM',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 118,
                'min_stock'     => 50,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
            [
                'sku'           => 'VVP-350',
                'barcode'       => '8997005490283 (350Ml)',
                'name'          => 'VIBE VODKA PREMIUM (350Ml)',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 2246,
                'min_stock'     => 100,
                'buy_price'     => 5000,
                'sell_price'    => 7500,
            ],
            [
                'sku'           => 'VDG-REG',
                'barcode'       => '8997005490290',
                'name'          => 'VIBE DRY GIN',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 1736,
                'min_stock'     => 100,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
            [
                'sku'           => 'VWR-REG',
                'barcode'       => '8997005490306',
                'name'          => 'VIBE WHITE RUM',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 4644,
                'min_stock'     => 100,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
            [
                'sku'           => 'VCC-REG',
                'barcode'       => '8997005490320',
                'name'          => 'VIBE CREME DE CACAO',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 936,
                'min_stock'     => 50,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
            [
                'sku'           => 'VCM-REG',
                'barcode'       => '8997005490337',
                'name'          => 'VIBE CREME DE MENTHE',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 875,
                'min_stock'     => 50,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
            [
                'sku'           => 'VAP-REG',
                'barcode'       => '8997005490351',
                'name'          => 'VIBE APRICOT',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 1492,
                'min_stock'     => 100,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
            [
                'sku'           => 'VAP-350',
                'barcode'       => '8997005490351 (350Ml)',
                'name'          => 'VIBE APRICOT (350Ml)',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 825,
                'min_stock'     => 50,
                'buy_price'     => 5000,
                'sell_price'    => 7500,
            ],
            [
                'sku'           => 'VPN-REG',
                'barcode'       => '8997005490368',
                'name'          => 'VIBE PINEAPPLE',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 285,
                'min_stock'     => 50,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
            [
                'sku'           => 'VCB-REG',
                'barcode'       => '8997005490375',
                'name'          => 'VIBE CHERRY BRANDY',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 221,
                'min_stock'     => 50,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
            [
                'sku'           => 'BAG-REG',
                'barcode'       => '8997005491259',
                'name'          => 'BLUE AGAVE',
                'category'      => 'Minuman',
                'unit'          => 'btl',
                'current_stock' => 59,
                'min_stock'     => 20,
                'buy_price'     => 15000,
                'sell_price'    => 22000,
            ],
        ];

        foreach ($products as $product) {
            if (isset($product['category'])) {
                $categoryName = $product['category'];
                $category = \App\Models\Category::firstOrCreate(['name' => $categoryName]);
                unset($product['category']);
                $product['category_id'] = $category->id;
            }
            Product::updateOrCreate(['sku' => $product['sku']], $product);
        }
    }
}
