<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('sptjm_reports', function (Blueprint $table) {
            $table->id();
            $table->foreignId('school_id')->constrained('schools')->onDelete('cascade');
            $table->foreignId('submitted_by')->constrained('users')->onDelete('restrict');
            $table->foreignId('verified_by')->nullable()->constrained('users')->onDelete('restrict');
            $table->string('report_period', 50);
            $table->integer('student_count');
            $table->string('sptjm_file_path');
            $table->enum('status', ['draft', 'submitted', 'verified', 'rejected'])->default('draft')->index();
            $table->text('rejection_notes')->nullable();
            $table->timestamp('submitted_at')->nullable()->index();
            $table->timestamp('verified_at')->nullable();
            $table->timestamps();
            
            $table->index(['school_id', 'status']);
            $table->index(['verified_by', 'status']);
            $table->index(['report_period', 'status']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('sptjm_reports');
    }
};
