<?php

declare(strict_types=1);

use Nyholm\Psr7\Factory\Psr17Factory;
use Pkirillw\MaxBotApi\Webhook\WebhookHandler;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\App;

return static function (App $app): void {
    $app->post('/webhook', WebhookHandler::class);

    $app->get('/health', function (ServerRequestInterface $request, ResponseInterface $response): ResponseInterface {
        $payload = json_encode(['ok' => true, 'time' => date('c')], JSON_UNESCAPED_UNICODE);
        $response->getBody()->write((string) $payload);
        return $response->withHeader('Content-Type', 'application/json');
    });
};
