<?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('posts', function (Blueprint $table) {
            // Ubah enum status tambah 'approved'
            $table->enum('status', ['draft', 'pending', 'approved', 'published', 'rejected'])
                ->default('draft')->change();

            $table->foreignId('approved_by')->nullable()->constrained('users')->after('reviewed_by');
            $table->timestamp('approved_at')->nullable()->after('approved_by');
        });
    }

    public function down(): void
    {
        Schema::table('posts', function (Blueprint $table) {
            $table->dropForeign(['approved_by']);
            $table->dropColumn(['approved_by', 'approved_at']);
            $table->enum('status', ['draft', 'pending', 'published', 'rejected'])
                ->default('draft')->change();
        });
    }
};
