<?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('barobill_card_transaction_hides', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id');
            $table->string('original_unique_key', 255)->comment('cardNum|useDt|approvalNum|amount');
            $table->string('card_num', 50)->default('');
            $table->string('use_date', 8)->default('');
            $table->string('approval_num', 50)->default('');
            $table->decimal('original_amount', 15, 2)->default(0);
            $table->string('merchant_name', 255)->default('');
            $table->unsignedBigInteger('hidden_by')->nullable();
            $table->timestamps();

            $table->index(['tenant_id', 'original_unique_key'], 'idx_tenant_unique_key');
            $table->index(['tenant_id', 'use_date'], 'idx_tenant_use_date');

            $table->foreign('tenant_id')->references('id')->on('tenants')->onDelete('cascade');
        });
    }

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