<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
 * Persist the reconciliation figures captured when a till session is closed.
 *
 * Previously the expected balance and the over/short variance were computed at
 * close time and written only to the audit log, which made them impossible to
 * report on — you could not ask "which tills came up short this week?" without
 * parsing audit JSON. Storing them on the session itself makes the shift
 * reconciliation queryable, and freezes the expected figure as it stood at
 * close (recomputing it later could drift if movements are ever backdated).
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('pos_sessions', function (Blueprint $table) {
            $table->decimal('expected_balance', 12, 2)->nullable()->after('closing_balance');
            $table->decimal('variance', 12, 2)->nullable()->after('expected_balance');
            $table->string('close_note', 500)->nullable()->after('variance');
        });
    }

    public function down(): void
    {
        Schema::table('pos_sessions', function (Blueprint $table) {
            $table->dropColumn(['expected_balance', 'variance', 'close_note']);
        });
    }
};
