<?php

namespace App\Models;

use Cviebrock\EloquentSluggable\Sluggable;
use Illuminate\Database\Eloquent\Model;

class WithdrawMethod extends Model
{
    use Sluggable;

    protected $guarded = ['id'];

    public $casts = [
        'fields' => 'array',
    ];

    public function sluggable(): array
    {
        return [
            'slug' => [
                'source' => 'name',
                'separator' => '-',
            ],
        ];
    }

    public function getSearchAttribute()
    {
        return [
            'name',
        ];
    }

    public function isValidPaymentAmount(float $amount)
    {
        return $amount >= $this->min && $amount <= $this->max;
    }

    public function totalCharge(float $amount)
    {
        $charge = 0;
        $charge = $this->percent_charge ? ($amount * $this->percent_charge) / 100 : 0;

        return $charge + $this->fixed_charge;
    }

    public function scopeActive($query)
    {
        return $query->where('status', 'active');
    }
}
