<?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::table('legal_pages', function (Blueprint $table): void {
            if (! Schema::hasColumn('legal_pages', 'meta_title')) {
                $table->string('meta_title')->nullable();
            }
            if (! Schema::hasColumn('legal_pages', 'meta_description')) {
                $table->text('meta_description')->nullable();
            }
            if (! Schema::hasColumn('legal_pages', 'og_image_path')) {
                $table->string('og_image_path')->nullable();
            }
            if (! Schema::hasColumn('legal_pages', 'canonical_url')) {
                $table->string('canonical_url')->nullable();
            }
            if (! Schema::hasColumn('legal_pages', 'status')) {
                $table->enum('status', ['draft', 'published'])->default('published')->index();
            }
            if (! Schema::hasColumn('legal_pages', 'is_indexable')) {
                $table->boolean('is_indexable')->default(true)->index();
            }
        });
    }

    public function down(): void
    {
        Schema::table('legal_pages', function (Blueprint $table): void {
            if (Schema::hasColumn('legal_pages', 'meta_title')) {
                $table->dropColumn('meta_title');
            }
            if (Schema::hasColumn('legal_pages', 'meta_description')) {
                $table->dropColumn('meta_description');
            }
            if (Schema::hasColumn('legal_pages', 'og_image_path')) {
                $table->dropColumn('og_image_path');
            }
            if (Schema::hasColumn('legal_pages', 'canonical_url')) {
                $table->dropColumn('canonical_url');
            }
            if (Schema::hasColumn('legal_pages', 'status')) {
                $table->dropColumn('status');
            }
            if (Schema::hasColumn('legal_pages', 'is_indexable')) {
                $table->dropColumn('is_indexable');
            }
        });
    }
};
