<?php

use Hyperf\Database\Schema\Blueprint;
use Hypervel\Database\Migrations\Migration;
use Hypervel\Support\Facades\Schema;

return new class extends Migration {

    public function up(): void
    {
        // Scope accounts to a specific store (NULL = global / Big-3 managed)
        Schema::table('accounts', function (Blueprint $table) {
            $table->unsignedBigInteger('store_id')->nullable()->index()->after('parent_id');
            $table->foreign('store_id')->references('id')->on('str')->nullOnDelete();
        });

        // Add missing columns referenced by AccountingController / AccountTransaction model
        Schema::table('account_transactions', function (Blueprint $table) {
            $table->string('flow', 16)->nullable()->index()->after('amount');
            $table->string('notes', 500)->nullable()->after('flow');
        });
    }

    public function down(): void
    {
        Schema::table('account_transactions', function (Blueprint $table) {
            $table->dropColumn(['flow', 'notes']);
        });

        Schema::table('accounts', function (Blueprint $table) {
            $table->dropForeign(['store_id']);
            $table->dropColumn('store_id');
        });
    }
};
