<?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('hr_offboarding_cases', function (Blueprint $table): void {
            $table->id();
            $table->foreignId('tenant_id')->constrained('tenants')->cascadeOnDelete();
            $table->foreignId('employee_id')->constrained('employees')->cascadeOnDelete();
            $table->enum('type', ['resignation', 'termination']);
            $table->enum('status', ['draft', 'submitted', 'approved', 'clearance', 'final_settlement', 'completed'])->default('draft');
            $table->text('reason');
            $table->date('last_working_date');
            $table->text('exit_interview_notes')->nullable();
            $table->text('clearance_notes')->nullable();
            $table->text('knowledge_transfer_notes')->nullable();
            $table->enum('final_settlement_status', ['pending', 'processing', 'paid', 'waived'])->default('pending');
            $table->boolean('experience_letter_issued')->default(false);
            $table->timestamp('deactivated_user_at')->nullable();
            $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamps();
            $table->index(['tenant_id', 'status']);
        });
        Schema::create('hr_offboarding_checklist_items', function (Blueprint $table): void {
            $table->id();
            $table->foreignId('case_id')->constrained('hr_offboarding_cases')->cascadeOnDelete();
            $table->enum('section', ['assets', 'accounts', 'documents', 'other']);
            $table->string('title');
            $table->boolean('is_done')->default(false);
            $table->timestamp('done_at')->nullable();
            $table->foreignId('done_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamps();
        });
    }

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