<?php

namespace App\Models;

use App\Enums\AdminNotificationType;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;

#[Fillable([
    'notify_new_user_registered',
    'notify_investment_pending',
    'notify_withdrawal_requested',
    'notify_kyc_submitted',
])]
class AdminNotificationSetting extends Model
{
    /**
     * Singleton de preferencias globales de correo para administradores.
     */
    public static function current(): self
    {
        return static::query()->firstOrCreate([], [
            'notify_new_user_registered' => true,
            'notify_investment_pending' => true,
            'notify_withdrawal_requested' => true,
            'notify_kyc_submitted' => true,
        ]);
    }

    public function isEnabled(AdminNotificationType $type): bool
    {
        return match ($type) {
            AdminNotificationType::NewUserRegistered => (bool) $this->notify_new_user_registered,
            AdminNotificationType::InvestmentPending => (bool) $this->notify_investment_pending,
            AdminNotificationType::WithdrawalRequested => (bool) $this->notify_withdrawal_requested,
            AdminNotificationType::KycSubmitted => (bool) $this->notify_kyc_submitted,
        };
    }

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'notify_new_user_registered' => 'boolean',
            'notify_investment_pending' => 'boolean',
            'notify_withdrawal_requested' => 'boolean',
            'notify_kyc_submitted' => 'boolean',
        ];
    }
}
