<?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('storage_usage_history', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');

            // 용량 정보
            $table->bigInteger('storage_used')->comment('사용량 (bytes)');
            $table->integer('file_count')->comment('파일 개수');

            // 폴더별 상세 (JSON)
            $table->json('folder_usage')->nullable()->comment('폴더별 용량 {"product": 1024000, "quality": 512000}');

            // 기록 시간
            $table->timestamp('recorded_at')->useCurrent()->comment('기록 시간');

            // 인덱스
            $table->index(['tenant_id', 'recorded_at'], 'idx_tenant_recorded');

            // 외래키
            $table->foreign('tenant_id')->references('id')->on('tenants')->onDelete('cascade');
        });
    }

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