<?php

declare(strict_types=1);

namespace App\Controllers;

use App\Core\Auth;
use App\Core\DB;
use App\Core\Request;
use App\Core\Response;
use App\Modules\Finance\Application\Services\FinanceRouteContext;
use App\Services\CheckAlertService;

final class CheckAlertController
{
    private FinanceRouteContext $routeContext;

    public function __construct()
    {
        $this->routeContext = new FinanceRouteContext();
    }

    public function handle(): void
    {
        Auth::requireLogin();
        require_permission('checks.view');
        $service = new CheckAlertService(DB::pdo());
        Response::view('pages/checks/alerts', array_merge(
            array_merge($service->data(Request::int('days', 7)), ['check_view_base_url' => $this->routeContext->checkViewPath()]),
            [
                'page_title' => 'تنبيهات الشيكات',
                'breadcrumbs' => [
                    $this->routeContext->dashboardCrumb(),
                    ['label' => 'الشيكات'],
                    ['label' => 'تنبيهات الشيكات'],
                ],
            ]
        ));
    }
}
