<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Notification;
use App\Services\System\NotificationService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class NotificationController extends Controller
{
    public function __construct(
        private readonly NotificationService $notificationService,
    ) {}

    public function index(Request $request): JsonResponse
    {
        return response()->json(
            $this->notificationService->listForUser($request->user()),
        );
    }

    public function markAsRead(Request $request, Notification $notification): JsonResponse
    {
        $this->notificationService->markAsRead($notification, $request->user());

        return response()->json(['success' => true]);
    }

    public function markAllAsRead(Request $request): JsonResponse
    {
        $this->notificationService->markAllAsRead($request->user());

        return response()->json(['success' => true]);
    }

    public function destroy(Request $request, Notification $notification): JsonResponse
    {
        $this->notificationService->delete($notification, $request->user());

        return response()->json(['success' => true]);
    }

    public function destroyAll(Request $request): JsonResponse
    {
        $this->notificationService->deleteAll($request->user());

        return response()->json(['success' => true]);
    }
}
