<?php

namespace Database\Seeders;

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

class CourseScheduleSeeder extends Seeder
{
    public function run(): void
    {
        DB::table('course_schedules')->truncate();

        // Kurs slug → id eşlemesi
        $courseIds = DB::table('courses')->pluck('id', 'slug');

        $schedules = [
            // ── ŞUBAT 2026 ─────────────────────────────────────────────────
            [
                'course_id' => $courseIds['stcw-temel-guvenlik'] ?? null,
                'start_date' => '2026-02-24',
                'end_date' => '2026-02-28',
                'location' => 'Kadıköy',
                'quota' => 20,
                'available_seats' => 8,
                'is_urgent' => false,
            ],
            [
                'course_id' => $courseIds['yat-kaptani-25-gt'] ?? null,
                'start_date' => '2026-02-26',
                'end_date' => '2026-02-28',
                'location' => 'Kadıköy',
                'quota' => 12,
                'available_seats' => 4,
                'is_urgent' => true,
            ],

            // ── MART 2026 ───────────────────────────────────────────────────
            [
                'course_id' => $courseIds['arpa-radar-simulator'] ?? null,
                'start_date' => '2026-03-03',
                'end_date' => '2026-03-05',
                'location' => 'Online',
                'quota' => 20,
                'available_seats' => 12,
                'is_urgent' => false,
            ],
            [
                'course_id' => $courseIds['gmdss-genel-telsiz-operatoru-goc'] ?? null,
                'start_date' => '2026-03-10',
                'end_date' => '2026-03-17',
                'location' => 'Kadıköy',
                'quota' => 15,
                'available_seats' => 6,
                'is_urgent' => true,
            ],
            [
                'course_id' => $courseIds['aff-yangin-sondurme'] ?? null,
                'start_date' => '2026-03-17',
                'end_date' => '2026-03-19',
                'location' => 'Kadıköy',
                'quota' => 20,
                'available_seats' => 10,
                'is_urgent' => false,
            ],
            [
                'course_id' => $courseIds['dizel-motor-teknigi'] ?? null,
                'start_date' => '2026-03-24',
                'end_date' => '2026-03-28',
                'location' => 'Kadıköy',
                'quota' => 15,
                'available_seats' => 9,
                'is_urgent' => false,
            ],

            // ── NİSAN 2026 ──────────────────────────────────────────────────
            [
                'course_id' => $courseIds['stcw-temel-guvenlik'] ?? null,
                'start_date' => '2026-04-07',
                'end_date' => '2026-04-11',
                'location' => 'Kadıköy',
                'quota' => 20,
                'available_seats' => 14,
                'is_urgent' => false,
            ],
            [
                'course_id' => $courseIds['yat-kaptani-149-gt-egitimi-temel'] ?? null,
                'start_date' => '2026-04-14',
                'end_date' => '2026-04-19',
                'location' => 'Kadıköy',
                'quota' => 12,
                'available_seats' => 3,
                'is_urgent' => true,
            ],
            [
                'course_id' => $courseIds['bst-yenileme'] ?? null,
                'start_date' => '2026-04-21',
                'end_date' => '2026-04-22',
                'location' => 'Online',
                'quota' => 30,
                'available_seats' => 20,
                'is_urgent' => false,
            ],
            [
                'course_id' => $courseIds['ecdis-tip-bazli-egitim'] ?? null,
                'start_date' => '2026-04-28',
                'end_date' => '2026-04-30',
                'location' => 'Kadıköy',
                'quota' => 15,
                'available_seats' => 7,
                'is_urgent' => false,
            ],

            // ── MAYIS 2026 ──────────────────────────────────────────────────
            [
                'course_id' => $courseIds['stcw-temel-guvenlik'] ?? null,
                'start_date' => '2026-05-05',
                'end_date' => '2026-05-09',
                'location' => 'Kadıköy',
                'quota' => 20,
                'available_seats' => 15,
                'is_urgent' => false,
            ],
            [
                'course_id' => $courseIds['yat-kaptani-3000-gt'] ?? null,
                'start_date' => '2026-05-12',
                'end_date' => '2026-05-23',
                'location' => 'Kadıköy',
                'quota' => 10,
                'available_seats' => 5,
                'is_urgent' => false,
            ],
            [
                'course_id' => $courseIds['makine-dairesi-operasyonu'] ?? null,
                'start_date' => '2026-05-19',
                'end_date' => '2026-05-21',
                'location' => 'Kadıköy',
                'quota' => 15,
                'available_seats' => 8,
                'is_urgent' => false,
            ],
        ];

        // Null olan course_id'leri filtrele (kurs bulunamadıysa atla)
        $validSchedules = array_filter($schedules, fn ($s) => $s['course_id'] !== null);

        foreach ($validSchedules as $schedule) {
            DB::table('course_schedules')->insert(array_merge($schedule, [
                'created_at' => now(),
                'updated_at' => now(),
            ]));
        }
    }
}
