<?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('app_versions', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('version_code')->unique()->comment('정수 비교용 버전 코드');
            $table->string('version_name', 20)->comment('표시용 버전명 (예: 0.2)');
            $table->string('platform', 10)->default('android')->comment('android/ios');
            $table->text('release_notes')->nullable()->comment('변경사항');
            $table->string('apk_path', 500)->nullable()->comment('스토리지 경로');
            $table->unsignedBigInteger('apk_size')->nullable()->comment('파일 크기(bytes)');
            $table->string('apk_original_name', 255)->nullable()->comment('원본 파일명');
            $table->boolean('force_update')->default(false)->comment('강제 업데이트 여부');
            $table->boolean('is_active')->default(true)->comment('활성 여부');
            $table->unsignedInteger('download_count')->default(0)->comment('다운로드 수');
            $table->timestamp('published_at')->nullable()->comment('배포일');
            $table->unsignedBigInteger('created_by')->nullable()->comment('생성자');
            $table->unsignedBigInteger('updated_by')->nullable()->comment('수정자');
            $table->timestamps();
            $table->softDeletes();

            $table->index(['platform', 'is_active']);
        });
    }

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