<?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('pension_case_interims', function (Blueprint $table) {
            $table->id();
            $table->foreignId('pension_case_id')->constrained()->cascadeOnDelete();
            $table->unsignedTinyInteger('interim_number');
            $table->date('interim_date')->nullable();
            $table->decimal('interim_amount', 12, 2)->nullable();
            $table->decimal('interim_capped_amount', 12, 2)->nullable();
            $table->decimal('net_to_client', 12, 2)->nullable();
            $table->decimal('vat_amount', 12, 2)->nullable();
            $table->decimal('cpf_fee_gross', 12, 2)->nullable();
            $table->decimal('cpf_fee_gross_capped', 12, 2)->nullable();
            $table->decimal('cpf_fee_net', 12, 2)->nullable();
            $table->decimal('cpf_fee_net_capped', 12, 2)->nullable();
            // Append-only — no updated_at
            $table->timestamp('created_at')->nullable()->useCurrent();

            $table->index('pension_case_id');
            $table->index('interim_number');
        });
    }

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