<?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
    {
        if (Schema::hasTable('daily_fund_transactions')) {
            return;
        }
        Schema::create('daily_fund_transactions', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id');
            $table->date('transaction_date');                    // 거래일
            $table->string('type', 20);                          // income, expense
            $table->string('time', 10)->nullable();              // 시간 (HH:MM)
            $table->unsignedBigInteger('account_id')->nullable(); // 계좌ID (corporate_cards 등과 연동 가능)
            $table->string('account_name', 50)->nullable();       // 계좌/은행명 (간편 저장용)
            $table->string('description', 200);                  // 적요
            $table->bigInteger('amount')->default(0);            // 금액
            $table->string('category', 50)->nullable();          // 카테고리
            $table->string('note', 200)->nullable();             // 비고
            $table->timestamps();
            $table->softDeletes();
            $table->index(['tenant_id', 'transaction_date']);
            $table->index(['tenant_id', 'type']);
        });
    }

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