<?php

namespace App\Services\System;

use App\Models\PushSubscription;

class PushSubscriptionService
{
    public function updateOrCreateSubscription(array $validated, int $userId): void
    {
        PushSubscription::updateOrCreate(
            [
                'user_id' => $userId,
                'endpoint' => $validated['endpoint'],
            ],
            [
                'public_key' => $validated['publicKey'],
                'auth_token' => $validated['authToken'],
            ]
        );
    }

    public function deleteSubscription(string $endpoint, int $userId): void
    {
        PushSubscription::where('user_id', $userId)
            ->where('endpoint', $endpoint)
            ->delete();
    }
}
