<?php

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

return new class extends Migration
{
    public function up(): void
    {
        $row = [
            'code' => 'grn_reversal',
            'name' => 'GRN Reversal (Admin Delete)',
            'direction' => 'out',
            'sort_order' => 99,
            'is_active' => true,
            'created_at' => now(),
            'updated_at' => now(),
        ];

        if (Schema::hasColumn('movement_types', 'tenant_id')) {
            $row['tenant_id'] = DB::table('movement_types')->value('tenant_id') ?? 1;
        }

        DB::table('movement_types')->insert($row);
    }

    public function down(): void
    {
        DB::table('movement_types')->where('code', 'grn_reversal')->delete();
    }
};
