<?php

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

return new class extends Migration
{
    public function up()
    {
        Schema::create('attendance', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id');
            $table->date('date');
            $table->enum('status', ['hadir', 'izin', 'alfa']);
            $table->datetime('check_in_time')->nullable(); // bisa kosong jika izin atau alfa
            $table->datetime('check_out_time')->nullable(); // bisa kosong jika izin atau alfa
            $table->text('notes')->nullable(); // catatan untuk izin atau alfa
            $table->timestamps();
            
            $table->foreign('user_id')->references('id')->on('users');
            $table->unique(['user_id', 'date']); // agar pegawai hanya bisa absen satu kali saja sehari
            
        });
    }

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