<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('barobill_bank_sync_status', function (Blueprint $table) {
            $table->id();
            $table->foreignId('tenant_id')->constrained()->onDelete('cascade');
            $table->string('bank_account_num', 50)->comment('계좌번호');
            $table->string('synced_year_month', 6)->comment('동기화 완료된 월 (YYYYMM)');
            $table->timestamp('synced_at')->comment('마지막 동기화 시각');
            $table->timestamps();

            $table->unique(
                ['tenant_id', 'bank_account_num', 'synced_year_month'],
                'bb_sync_status_unique'
            );
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('barobill_bank_sync_status');
    }
};
