<?php

namespace App\Services\Providers;

use App\Models\DeviceToken;
use RuntimeException;

class PushProvider
{
    public function __construct(
        private readonly ExpoPushProvider $expo,
        private readonly FcmPushProvider $fcm,
        private readonly ApnsPushProvider $apns,
    ) {}

    public function send(DeviceToken $device, string $title, string $body, array $data = []): ?string
    {
        return match ($device->provider) {
            'expo' => $this->expo->send($device, $title, $body, $data),
            'fcm' => $this->fcm->send($device, $title, $body, $data),
            'apns' => $this->apns->send($device, $title, $body, $data),
            default => throw new RuntimeException("Unsupported push provider: {$device->provider}"),
        };
    }
}
