<?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('absensi_harian', function (Blueprint $table) {
            $table->id();
            $table->foreignId('siswa_id')->constrained('siswas')->onDelete('cascade');
            $table->date('tanggal');
            $table->enum('status', ['Hadir', 'Alpa', 'Izin', 'Sakit'])->default('Hadir');
            $table->string('keterangan', 255)->nullable(); // alasan izin/sakit jika ada
            $table->string('sumber', 20)->default('manual'); // selalu 'manual'
            $table->foreignId('input_by')->nullable()->constrained('users')->onDelete('set null'); // siapa yang input
            $table->timestamps();

            // Satu siswa hanya boleh 1 record per hari
            $table->unique(['siswa_id', 'tanggal']);
        });
    }

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