<?php

namespace App\Services;

use App\Models\User;
use Illuminate\Http\JsonResponse;

class PushSubscriptionService
{
    public function store(
        User $user,
        string $endpoint,
        ?string $publicKey,
        ?string $authToken,
        ?string $contentEncoding,
    ): JsonResponse {
        $user->updatePushSubscription(
            $endpoint,
            $publicKey,
            $authToken,
            $contentEncoding,
        );

        return response()->json(['message' => 'Subscription saved.']);
    }

    public function destroy(User $user, string $endpoint): JsonResponse
    {
        $user->deletePushSubscription($endpoint);

        return response()->json(['message' => 'Subscription removed.']);
    }
}
