<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up()
    {
        if (!Schema::hasTable('application_files')) {
            Schema::create('application_files', function (Blueprint $table) {
                $table->id();
                $table->foreignId('application_id')->constrained()->cascadeOnDelete();
                $table->string('architecture')->default('Universal');
                $table->string('file_path');
                $table->unsignedBigInteger('file_size')->default(0);
                $table->timestamps();
            });
        }

        Schema::table('applications', function (Blueprint $table) {
            $table->string('download_url')->nullable()->change();
        });
    }

    public function down()
    {
        Schema::dropIfExists('application_files');
        Schema::table('applications', function (Blueprint $table) {
            $table->string('download_url')->nullable(false)->change();
        });
    }
};
