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

namespace Kufer\Web\KuferTools\Dozent\Wunschtermine\Neu;

use Kufer\Web\KuferTools\Basis\UseCase\ToolResponse;
use Kufer\Web\KuferTools\Utils\ResponseStrategies\ResponseMitRahmen;
use Kufer\Web\KuferTools\Utils\ResponseStrategies\ResponseWss;
use Kufer\Web\KuferTools\Utils\StatusMessages\StatusMessageContainer;
use Kufer\Web\Classes\Db\DBWorkWunschtermine;

class WunschterminNeuUseCase extends \Kufer\Web\KuferTools\Basis\UseCase\ToolUseCase
{
  
  protected $dbwWunschtermine;

  public function __construct($request, $response = null)
  {
    parent::__construct($request, $response ?? new WunschterminNeuResponse());
    $this->dbwWunschtermine = DBWorkWunschtermine::getDefaultInstance();
  }

  public static function getToolId()
  {
    return \ToolsAPI::TOOL_DOZ_WUNSCHTERMINE;
  }

  public static function getToolSectionId()
  {
    return 799;
  }

  public function hasAccess($pToolSectionId = null)
  {
    if (!parent::hasAccess($pToolSectionId)) {
      return false;
    }

    

    return true;
  }

  public function action()
  {
    $this->handleResponseStrategies();
    $this->response->wunschtermin = $this->request->wunschtermin ?? $this->dbwWunschtermine->getNewObject();

    if (isset($this->request->wunschtermin)) {
      $smc = StatusMessageContainer::getSharedInstance();
      $this->response->info = $smc->getMessageStringInfo();
      $this->response->success = $smc->getMessageStringSuccess();
      $this->response->warning = $smc->getMessageStringWarning();
      $this->response->error = $smc->getMessageStringError();
    } else {
      
      $now = \DateTimeOperations::getDateNow();
      $this->response->wunschtermin->datvon = $now;
      $this->response->wunschtermin->datbis = $now;
      $this->response->wunschtermin->wotag = 'alle';
    }

    return $this->response;
  }

  protected function getResponseStrategies()
  {
    return array(
      new ResponseMitRahmen($this),
      new ResponseWss($this),
      new \Kufer\Web\KuferTools\Utils\ResponseStrategies\ResponseWithToolSettings($this)
    );
  }
}

class WunschterminNeuRequest
{
  public $wunschtermin;
  public $id;

  public $columnValues;
  public $wssHandler;
}

class WunschterminNeuResponse extends ToolResponse
{
  public $menuPunkte;
  public $user;
  public $wunschtermin;
  public $columns;
}