<?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('payrolls', function (Blueprint $table) {
            $table->id();

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

            $table->unsignedTinyInteger('payroll_month');
            $table->unsignedSmallInteger('payroll_year');

            $table->date('payroll_date')->nullable();

            $table->enum('status', ['draft', 'finalized', 'paid_partial', 'paid_full', 'cancelled'])
                ->default('draft');

            $table->text('notes')->nullable();

            $table->timestamps();

            $table->unique(['user_id', 'payroll_month', 'payroll_year']);
            $table->index(['user_id', 'status']);
        });
    }

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