<?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('cutis', function (Blueprint $table) {
            $table->id();
            $table->foreignId('karyawan_id')->constrained('karyawans')->cascadeOnDelete();
            $table->date('tanggal_mulai');
            $table->date('tanggal_selesai');
            $table->integer('durasi_hari');
            $table->string('jenis')->default('tahunan'); // tahunan|besar|melahirkan|penting|lainnya
            $table->text('keterangan')->nullable();
            $table->string('bukti_file')->nullable();
            $table->enum('status', ['pending','disetujui','ditolak'])->default('pending');
            $table->foreignId('disetujui_oleh')->nullable()->constrained('users')->nullOnDelete();
            $table->text('catatan_admin')->nullable();
            $table->timestamps();
        });

        // Tabel jatah cuti per karyawan per tahun
        Schema::create('jatah_cutis', function (Blueprint $table) {
            $table->id();
            $table->foreignId('karyawan_id')->constrained('karyawans')->cascadeOnDelete();
            $table->year('tahun');
            $table->integer('jatah_hari')->default(12);
            $table->integer('terpakai_hari')->default(0);
            $table->timestamps();

            $table->unique(['karyawan_id', 'tahun']);
        });
    }

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