<?php

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

/**
 * Phase-2 placeholders for auto/generated cover images.
 * No generation pipeline in phase 1 — queue/scripts will fill these later.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('articles', function (Blueprint $table) {
            if (! Schema::hasColumn('articles', 'cover_disk')) {
                $table->string('cover_disk')->nullable()->after('legacy_attachments');
            }
            if (! Schema::hasColumn('articles', 'cover_path')) {
                $table->string('cover_path')->nullable()->after('cover_disk');
            }
            if (! Schema::hasColumn('articles', 'cover_source')) {
                $table->string('cover_source', 32)->default('none')->after('cover_path');
            }
            if (! Schema::hasColumn('articles', 'cover_status')) {
                $table->string('cover_status', 32)->default('none')->after('cover_source');
            }
            if (! Schema::hasColumn('articles', 'cover_generated_at')) {
                $table->timestamp('cover_generated_at')->nullable()->after('cover_status');
            }
        });
    }

    public function down(): void
    {
        Schema::table('articles', function (Blueprint $table) {
            foreach (['cover_disk', 'cover_path', 'cover_source', 'cover_status', 'cover_generated_at'] as $column) {
                if (Schema::hasColumn('articles', $column)) {
                    $table->dropColumn($column);
                }
            }
        });
    }
};
