<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

class ManualPaymentGateway extends Model
{
    protected $guarded = [];

    protected static function booted(): void
    {
        static::saving(function (ManualPaymentGateway $gateway) {
            if (blank($gateway->slug)) {
                $gateway->slug = Str::slug($gateway->name_en ?: $gateway->name_ar ?: Str::random(8));
            }

            if (blank($gateway->supported_currencies)) {
                $gateway->supported_currencies = ['EGP'];
            }
        });
    }

    protected function casts(): array
    {
        return [
            'is_active' => 'boolean',
            'receiver_data' => 'array',
            'required_fields' => 'array',
            'supported_currencies' => 'array',
            'country_codes' => 'array',
            'risk_rules' => 'array',
            'requires_proof' => 'boolean',
            'proof_is_required' => 'boolean',
            'min_amount_minor' => 'integer',
            'max_amount_minor' => 'integer',
            'fee_value' => 'integer',
            'proof_max_mb' => 'integer',
            'review_sla_minutes' => 'integer',
            'expires_after_minutes' => 'integer',
        ];
    }

    public function submissions()
    {
        return $this->hasMany(ManualPaymentSubmission::class);
    }
}
