<?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('condolence_expenses', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id')->index();
            $table->date('event_date')->nullable()->comment('경조사일자');
            $table->date('expense_date')->nullable()->comment('지출일자');
            $table->string('partner_name', 100)->comment('거래처명/대상자');
            $table->string('description', 200)->nullable()->comment('내역');
            $table->string('category', 20)->default('congratulation')->comment('구분: congratulation(축의), condolence(부조)');
            $table->boolean('has_cash')->default(false)->comment('부조금 여부');
            $table->string('cash_method', 30)->nullable()->comment('지출방법: cash, transfer, card');
            $table->integer('cash_amount')->default(0)->comment('부조금 금액');
            $table->boolean('has_gift')->default(false)->comment('선물 여부');
            $table->string('gift_type', 50)->nullable()->comment('선물 종류');
            $table->integer('gift_amount')->default(0)->comment('선물 금액');
            $table->integer('total_amount')->default(0)->comment('총금액');
            $table->json('options')->nullable();
            $table->text('memo')->nullable()->comment('비고');
            $table->unsignedBigInteger('created_by')->nullable();
            $table->timestamps();
            $table->softDeletes();

            $table->index(['tenant_id', 'event_date']);
            $table->index(['tenant_id', 'category']);
        });
    }

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