<?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('vat_records')) {
            return;
        }
        Schema::create('vat_records', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id');
            $table->string('period', 20);                   // 2026-1H, 2025-2H
            $table->string('type', 20)->default('sales');    // sales, purchase
            $table->string('partner_name', 100);             // 거래처명
            $table->string('invoice_no', 50);                // 세금계산서번호
            $table->date('invoice_date')->nullable();        // 발행일
            $table->bigInteger('supply_amount')->default(0); // 공급가액
            $table->bigInteger('vat_amount')->default(0);    // 부가세
            $table->bigInteger('total_amount')->default(0);  // 합계
            $table->string('status', 20)->default('pending');// pending, filed, paid
            $table->text('memo')->nullable();
            $table->timestamps();
            $table->softDeletes();
            $table->index(['tenant_id', 'period']);
            $table->index(['tenant_id', 'type']);
        });
    }

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