<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class PartnerWalletSetting extends Model
{
    use HasFactory;

    const PAYMENT_ZAIN_CASH = 'zain_cash';
    const PAYMENT_MASTERCARD = 'mastercard';
    const PAYMENT_AMAN_CARD = 'aman_card';

    protected $fillable = [
        'partner_wallet_id',
        'payment_methods',
        'min_topup_amount',
        'max_topup_amount',
        'allow_negative_balance',
        'zain_cash_merchant_id',
        'notes',
    ];

    protected $casts = [
        'payment_methods' => 'array',
        'min_topup_amount' => 'decimal:2',
        'max_topup_amount' => 'decimal:2',
        'allow_negative_balance' => 'boolean',
    ];

    public function partnerWallet(): BelongsTo
    {
        return $this->belongsTo(PartnerWallet::class);
    }

    /**
     * هل وسيلة الدفع مفعّلة؟
     */
    public function hasPaymentMethod(string $method): bool
    {
        $methods = $this->payment_methods ?? [];
        return in_array($method, $methods);
    }
}
