<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('trainings', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->text('summary')->nullable();
            $table->date('start_date');
            $table->date('end_date');
            $table->integer('duration_days');
            $table->string('location');
            $table->text('course_outline')->nullable();
            $table->integer('expected_participants')->default(0);
            $table->string('trainer_name')->nullable();
            $table->string('supervisor_name')->nullable();
            $table->text('remarks')->nullable();
            $table->timestamps();
            $table->softDeletes();
        });

        // Pivot table for training participants
        Schema::create('ndrt_officer_training', function (Blueprint $table) {
            $table->id();
            $table->foreignId('ndrt_officer_id')->constrained()->onDelete('cascade');
            $table->foreignId('training_id')->constrained()->onDelete('cascade');
            $table->boolean('attended')->default(true);
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('ndrt_officer_training');
        Schema::dropIfExists('trainings');
    }
};