<?php

namespace Database\Seeders;

use App\Models\Produk;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class ProdukSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $csvFile = fopen(base_path("database/seeders/data_csv/produk.csv"), "r");

        $firstline = true;
        while (($data = fgetcsv($csvFile, 2000, ",")) !== FALSE) {
            if (!$firstline) {
                Produk::create([
                    'kategori_produk_id' => $data['0'] ?? '',
                    "kode_produk" => $data['1'] ?? '',
                    "nama_produk" => $data['2'] ?? '',
                    "deskripsi_produk" => $data['3'] ?? null,
                    "varian_produk" => $data['4'] ?? null,
                    "harga_produk" => $data['5'] ?? '',
                    "urutan" => $data['6'] == "" ? null : $data['6'],
                ]);
            }
            $firstline = false;
        }
    }
}
