<?php

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

class UpdateOrdersTable extends Migration
{
    public function up()
    {
        Schema::table('orders', function (Blueprint $table) {
            $table->string('payment_status')->default('waiting')->notNullable()->change();
        });

        DB::statement("
            ALTER TABLE orders 
            ADD CONSTRAINT payment_status_check 
            CHECK (payment_status IN ('waiting', 'cancelled', 'payed', 'cash', 'review', 'processing'))
        ");
    }

    public function down()
    {
        DB::statement("
            ALTER TABLE orders 
            DROP CONSTRAINT IF EXISTS payment_status_check
        ");

        Schema::table('orders', function (Blueprint $table) {
            $table->string('payment_status')->nullable()->default(null)->change();
        });
    }
}
