<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\Divisi;
use App\Models\Vehicle;
use Illuminate\Support\Facades\DB;

class VehicleSeeder extends Seeder
{
    /**
     * Jalankan database seeds.
     */
    public function run(): void
    {
        // 1. Isi Tabel Divisis sesuai gambar database
        $divisis = [
            ['nama' => 'Dalduk KB'],
            ['nama' => 'PPA'],
            ['nama' => 'PUG-PHA'],
            ['nama' => 'Sekretariat'],
            ['nama' => 'UPTD PPA'],
        ];

        foreach ($divisis as $divisi) {
            Divisi::updateOrCreate(['nama' => $divisi['nama']], $divisi);
        }

        // 2. Ambil ID Sekretariat untuk contoh kendaraan
        $sekretariatId = Divisi::where('nama', 'Sekretariat')->first()->id;

        // 3. Isi Tabel Vehicles (Plat L Surabaya)
        
        // Unit 1: Mobil Dinas (Avanza)
        Vehicle::updateOrCreate(
            ['plate_number' => 'L 1024 AP'],
            [
                'name' => 'Toyota Avanza (Dinas)',
                'type' => 'mobil',
                'brand' => 'Toyota',
                'model' => 'Avanza 1.3 G MT',
                'year' => 2022,
                'color' => 'Hitam',
                'fuel_type' => 'bensin',
                'capacity' => 7,
                'status' => 'available',
                'divisi_id' => $sekretariatId,
                'description' => 'Kendaraan operasional dinas Sekretariat',
                'last_service' => '2024-11-15',
                'next_service' => '2025-02-15',
                'image_path' => null,
            ]
        );

        // Unit 2: Sepeda Motor Dinas (Vario)
        Vehicle::updateOrCreate(
            ['plate_number' => 'L 4567 BS'],
            [
                'name' => 'Honda Vario (Dinas)',
                'type' => 'motor',
                'brand' => 'Honda',
                'model' => 'Vario 150',
                'year' => 2021,
                'color' => 'Hitam',
                'fuel_type' => 'bensin',
                'capacity' => 2,
                'status' => 'available',
                'divisi_id' => $sekretariatId,
                'description' => 'Motor dinas operasional lapangan',
                'last_service' => '2024-12-01',
                'next_service' => '2025-03-01',
            ]
        );

        // Unit 3: Mobil Dinas Tambahan (Innova)
        Vehicle::updateOrCreate(
            ['plate_number' => 'L 1945 AA'],
            [
                'name' => 'Toyota Innova Zenix (Dinas)',
                'type' => 'mobil',
                'brand' => 'Toyota',
                'model' => 'Innova Zenix V Hybrid',
                'year' => 2023,
                'color' => 'Putih',
                'fuel_type' => 'listrik',
                'capacity' => 7,
                'status' => 'available',
                'divisi_id' => $sekretariatId,
                'description' => 'Kendaraan dinas pimpinan',
                'last_service' => '2024-10-20',
                'next_service' => '2025-04-20',
            ]
        );

        // Unit 4: Sepeda Motor Dinas Tambahan (PCX)
        Vehicle::updateOrCreate(
            ['plate_number' => 'L 2234 OP'],
            [
                'name' => 'Honda PCX (Dinas)',
                'type' => 'motor',
                'brand' => 'Honda',
                'model' => 'PCX 160 ABS',
                'year' => 2023,
                'color' => 'Merah',
                'fuel_type' => 'bensin',
                'capacity' => 2,
                'status' => 'available',
                'divisi_id' => $sekretariatId,
                'description' => 'Motor dinas operasional administrasi',
                'last_service' => '2024-09-10',
                'next_service' => '2025-01-10',
            ]
        );

        // Unit 5: Mobil Operasional (Hiace)
        Vehicle::updateOrCreate(
            ['plate_number' => 'L 7001 XY'],
            [
                'name' => 'Toyota Hiace (Dinas)',
                'type' => 'mobil',
                'brand' => 'Toyota',
                'model' => 'Hiace Premio',
                'year' => 2022,
                'color' => 'Silver',
                'fuel_type' => 'diesel',
                'capacity' => 12,
                'status' => 'available',
                'divisi_id' => $sekretariatId,
                'description' => 'Kendaraan dinas angkutan personel',
                'last_service' => '2024-08-05',
                'next_service' => '2025-02-05',
            ]
        );
    }
}