<?php

namespace Modules\Announcement\Http\Controllers\Api;

use App\Http\Controllers\Api\ApiController;
use Illuminate\Http\Request;
use Modules\Announcement\Entities\Device;

class DotAnnouncementsController extends ApiController
{
    /**
     * Handle the incoming request.
     */
    public function __invoke(Request $request)
    {
        $token = $request->header('X-Device-Id');

        return $this->json([
            'dot' => Device::where('token', $token)->first()?->unreadAnnouncements()->active()->count()
        ]);
    }
}
