<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */

namespace Kufer\Web\KuferTools\Allgemein\Heartbeat\Heartbeat;

use Kufer\Web\KuferTools\Basis\Controller\AjaxNoContainerToolController;
use Kufer\Web\KuferTools\Basis\Presenter\JsonPresenterStringOnly;
use Kufer\Web\KuferTools\Basis\Controller\SimpleJsonResponseController;

class HeartbeatController extends AjaxNoContainerToolController
{
  protected function getUseCase(): \Kufer\Web\KuferTools\Basis\UseCase\UseCase
  {
    return new HeartbeatUseCase($this->getRequestObj());
  }

  protected function getAccessDeniedController()
  {
    $response = new class() {
      public $success;
      public $error_msg;
    };

    $response->success = false;
    $response->error_msg = 'Nicht eingeloggt';

    return new SimpleJsonResponseController(json_encode(\StringOperations::objectConvertStringEncoding($response, \CodingOperations::getInternalEncoding(), UTF_8)));
  }

  protected function getNotLoggedController()
  {
    return $this->getAccessDeniedController();
  }

  protected function getRequestObj()
  {
    return new HeartbeatRequest();
  }

  protected function getPresenter($pUseCaseResponse)
  {
    return new JsonPresenterStringOnly($pUseCaseResponse);
  }
}