<?php

namespace Database\Seeders;

use App\Models\PaymentMethod;
use Illuminate\Database\Seeder;

class PaymentMethodSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $cashAccount = \App\Models\Account::where('code', '1110')->first(); // Cash Drawer
        $bankAccount = \App\Models\Account::where('code', '1200')->first(); // Bank Account
        
        $methods = [
            [
                'name' => 'Cash',
                'name_ar' => 'نقدي',
                'code' => 'cash',
                'icon' => 'fas fa-money-bill-wave',
                'is_default' => true,
                'account_id' => $cashAccount?->id,
            ],
            [
                'name' => 'Card Payment',
                'name_ar' => 'بطاقة',
                'code' => 'card',
                'icon' => 'fas fa-credit-card',
                'is_default' => false,
                'account_id' => $bankAccount?->id,
            ],
            [
                'name' => 'Bank Transfer',
                'name_ar' => 'تحويل بنكي',
                'code' => 'bank',
                'icon' => 'fas fa-university',
                'is_default' => false,
                'account_id' => $bankAccount?->id,
            ],
            [
                'name' => 'Mobile Payment',
                'name_ar' => 'دفع عبر الهاتف',
                'code' => 'mobile',
                'icon' => 'fas fa-mobile-alt',
                'is_default' => false,
                'account_id' => $bankAccount?->id,
            ],
        ];

        foreach ($methods as $index => $method) {
            \App\Models\PaymentMethod::updateOrCreate(
                ['code' => $method['code']],
                array_merge($method, ['sort_order' => $index])
            );
        }
    }
}
