<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('orders', function (Blueprint $table) {

            // waktu OTP masuk / order success
            if (!Schema::hasColumn('orders', 'completed_at')) {
                $table->timestamp('completed_at')->nullable()->after('otp');
            }

            // waktu order di finish ke provider
            if (!Schema::hasColumn('orders', 'finished_at')) {
                $table->timestamp('finished_at')->nullable()->after('completed_at');
            }

        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('orders', function (Blueprint $table) {

            if (Schema::hasColumn('orders', 'finished_at')) {
                $table->dropColumn('finished_at');
            }

            if (Schema::hasColumn('orders', 'completed_at')) {
                $table->dropColumn('completed_at');
            }

        });
    }
};
