<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class KegiatanSeeder extends Seeder
{
    /**
     * Jalankan seeder untuk mengisi data program kegiatan bantuan dinamis.
     */
    public function run(): void
    {
        Schema::disableForeignKeyConstraints();
        DB::table('kegiatan')->truncate();
        DB::table('barang_kegiatan')->truncate();
        DB::table('syarat_kegiatan')->truncate();
        DB::table('kuota_kabupaten')->truncate();
        Schema::enableForeignKeyConstraints();

        // 1. Program Saprodi Padi Unggul TA 2026
        $padiId = DB::table('kegiatan')->insertGetId([
            'nama_kegiatan' => 'Saprodi Padi Unggul',
            'tahun_anggaran' => '2026',
            'is_active' => true,
            'created_at' => now(),
            'updated_at' => now(),
        ]);

        // Detail Item Barang Bantuan Padi
        DB::table('barang_kegiatan')->insert([
            ['kegiatan_id' => $padiId, 'nama_barang' => 'Benih Padi Inpari 32', 'satuan' => 'Kg', 'created_at' => now(), 'updated_at' => now()],
            ['kegiatan_id' => $padiId, 'nama_barang' => 'Pupuk NPK Non-Subsidi', 'satuan' => 'Kg', 'created_at' => now(), 'updated_at' => now()],
            ['kegiatan_id' => $padiId, 'nama_barang' => 'Pestisida Cair', 'satuan' => 'Liter', 'created_at' => now(), 'updated_at' => now()],
        ]);

        // Aturan Persyaratan Berkas Padi
        DB::table('syarat_kegiatan')->insert([
            ['kegiatan_id' => $padiId, 'nama_syarat' => 'Polygon Lokasi Lahan', 'tipe_file' => 'polygon', 'is_required' => true, 'bobot_nilai' => 40.00, 'created_at' => now(), 'updated_at' => now()],
            ['kegiatan_id' => $padiId, 'nama_syarat' => 'Surat Keterangan Desa', 'tipe_file' => 'pdf', 'is_required' => true, 'bobot_nilai' => 30.00, 'created_at' => now(), 'updated_at' => now()],
            ['kegiatan_id' => $padiId, 'nama_syarat' => 'Foto Lokasi Kelompok', 'tipe_file' => 'image', 'is_required' => true, 'bobot_nilai' => 30.00, 'created_at' => now(), 'updated_at' => now()],
        ]);

        // Alokasi Kuota Kabupaten Padi
        DB::table('kuota_kabupaten')->insert([
            ['kegiatan_id' => $padiId, 'regency_id' => 1, 'kuota_luas' => 15.00, 'created_at' => now(), 'updated_at' => now()], // Demak
            ['kegiatan_id' => $padiId, 'regency_id' => 2, 'kuota_luas' => 8.00, 'created_at' => now(), 'updated_at' => now()],  // Temanggung
        ]);


        // 2. Program Bantuan Pupuk Jagung Hibrida TA 2026
        $jagungId = DB::table('kegiatan')->insertGetId([
            'nama_kegiatan' => 'Bantuan Pupuk Jagung Hibrida',
            'tahun_anggaran' => '2026',
            'is_active' => true,
            'created_at' => now(),
            'updated_at' => now(),
        ]);

        // Detail Item Barang Bantuan Jagung
        DB::table('barang_kegiatan')->insert([
            ['kegiatan_id' => $jagungId, 'nama_barang' => 'Benih Jagung Hibrida', 'satuan' => 'Kg', 'created_at' => now(), 'updated_at' => now()],
            ['kegiatan_id' => $jagungId, 'nama_barang' => 'Pupuk Organik Padat', 'satuan' => 'Kg', 'created_at' => now(), 'updated_at' => now()],
        ]);

        // Aturan Persyaratan Berkas Jagung
        DB::table('syarat_kegiatan')->insert([
            ['kegiatan_id' => $jagungId, 'nama_syarat' => 'Polygon Plot Sawah', 'tipe_file' => 'polygon', 'is_required' => true, 'bobot_nilai' => 50.00, 'created_at' => now(), 'updated_at' => now()],
            ['kegiatan_id' => $jagungId, 'nama_syarat' => 'Surat Pengantar Dinas Kab', 'tipe_file' => 'pdf', 'is_required' => true, 'bobot_nilai' => 50.00, 'created_at' => now(), 'updated_at' => now()],
        ]);

        // Alokasi Kuota Kabupaten Jagung
        DB::table('kuota_kabupaten')->insert([
            ['kegiatan_id' => $jagungId, 'regency_id' => 1, 'kuota_luas' => 10.00, 'created_at' => now(), 'updated_at' => now()], // Demak
            ['kegiatan_id' => $jagungId, 'regency_id' => 2, 'kuota_luas' => 12.00, 'created_at' => now(), 'updated_at' => now()],  // Temanggung
        ]);
    }
}