<?php

namespace App\Services\Packages;

use App\Models\Tenant;

class TenantNotificationPreferences
{
    private const DEFAULTS = [
        'photo_thresholds' => true,
        'photo_limits' => true,
        'guest_thresholds' => true,
        'guest_limits' => true,
        'gallery_warnings' => true,
        'gallery_expired' => true,
        'event_thresholds' => true,
        'event_limits' => true,
        'package_expiring' => true,
        'package_expired' => true,
    ];

    public static function defaults(): array
    {
        return self::DEFAULTS;
    }

    public function shouldNotify(Tenant $tenant, string $preferenceKey): bool
    {
        $preferences = $tenant->notification_preferences ?? [];

        if (! is_array($preferences)) {
            $preferences = [];
        }

        if (array_key_exists($preferenceKey, $preferences)) {
            return (bool) $preferences[$preferenceKey];
        }

        return self::DEFAULTS[$preferenceKey] ?? true;
    }
}
