<?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::table('attendances', function (Blueprint $table) {
            $table->dropUnique('attendances_user_id_date_unique');
        });

        Schema::create('pengajuan', function (Blueprint $table) {
            $table->id();

            // FK ke users.id
            $table->foreignId('id_user')
                ->constrained('users')
                ->onDelete('cascade');

            $table->foreignId('id_attendance')
                ->constrained('attendances')
                ->onDelete('cascade');

            $table->date('date');
            $table->string('keterangan', 255);
            $table->string('url_bukti', 255);
            $table->enum('status', ['diajukan', 'disetujui', 'ditolak'])
                ->default('diajukan');
            $table->timestamps();
        });
    }

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

        Schema::table('attendances', function (Blueprint $table) {
            $table->unique(['user_id', 'date']);
        });
    }
};
