<?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::create('payment_methods', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('slug')->unique();
            $table->enum('status', ['active', 'inactive'])->default('active');
            $table->enum('fee_type', ['fixed', 'percentage'])->default('fixed');
            $table->decimal('fee_value', 10, 2)->default(0);
            $table->string('icon')->nullable();
            $table->unsignedInteger('sort_order')->default(0);
            $table->timestamps();
        });

        $defaults = [
            ['name' => 'كاش عند الاستلام', 'slug' => 'cash', 'status' => 'active', 'fee_type' => 'fixed', 'fee_value' => 0, 'icon' => 'heroicon-o-banknotes', 'sort_order' => 1],
            ['name' => 'تحويل بنكي', 'slug' => 'transfer', 'status' => 'active', 'fee_type' => 'fixed', 'fee_value' => 0, 'icon' => 'heroicon-o-building-library', 'sort_order' => 2],
            ['name' => 'فودافون كاش', 'slug' => 'vodafone_cash', 'status' => 'active', 'fee_type' => 'fixed', 'fee_value' => 5, 'icon' => 'heroicon-o-device-phone-mobile', 'sort_order' => 3],
            ['name' => 'فيزا', 'slug' => 'visa', 'status' => 'active', 'fee_type' => 'percentage', 'fee_value' => 3, 'icon' => 'heroicon-o-credit-card', 'sort_order' => 4],
        ];

        foreach ($defaults as $i => $row) {
            \DB::table('payment_methods')->insert(array_merge($row, [
                'created_at' => now(),
                'updated_at' => now(),
            ]));
        }
    }

    public function down(): void
    {
        Schema::dropIfExists('payment_methods');
    }
};
