<?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('vehicle_maintenances', function (Blueprint $table) {
            $table->id();
            $table->foreignId('tenant_id')->constrained()->cascadeOnDelete();
            $table->foreignId('vehicle_id')->constrained('corporate_vehicles')->cascadeOnDelete();

            $table->date('date');                              // 날짜
            $table->string('category', 20);                    // 분류 (주유, 정비, 보험, 세차, 주차, 통행료, 검사, 기타)
            $table->string('description', 200)->nullable();    // 내용
            $table->unsignedBigInteger('amount')->default(0);  // 금액
            $table->unsignedInteger('mileage')->nullable();    // 주행거리(km)
            $table->string('vendor', 100)->nullable();         // 거래처
            $table->text('memo')->nullable();                  // 메모

            $table->timestamps();
            $table->softDeletes();

            // 인덱스
            $table->index(['tenant_id', 'vehicle_id', 'date']);
            $table->index(['tenant_id', 'category']);
        });
    }

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