<?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('orders', function (Blueprint $table) {
            $table->string('payment_receipt')->nullable()->after('payment_fee');
            $table->enum('payment_status', ['pending', 'confirmed', 'rejected'])
                ->default('pending')
                ->after('payment_receipt');
        });

        // الطلبات النقدية (كاش) تعتبر مؤكدة افتراضياً
        \DB::table('orders')->where('payment_method', 'cash')->update(['payment_status' => 'confirmed']);
    }

    public function down(): void
    {
        Schema::table('orders', function (Blueprint $table) {
            $table->dropColumn(['payment_receipt', 'payment_status']);
        });
    }
};
