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

namespace Kufer\Web\KuferTools\Basis\DozentenInfo\UpdateDozent\HandleDozentUpdate;

use Kufer\Web\KuferTools\Utils\DozentenHandler\DozentUpdater;

abstract class HandleDozentUpdateUseCase extends \Kufer\Web\KuferTools\Basis\UseCase\EinzelDozentUseCase
{
  public function __construct($request, $response = null)
  {
    parent::__construct($request, $response ?? new HandleDozentUpdateResponse());
  }

  public function action()
  {
    $origDozent = $this->getDozent();
    $dozentUpdater = new DozentUpdater($this->toolSettings);
    list($statusCode, $wrongFields) = $dozentUpdater->handleDozentUpdate($this->request->wssHandler, $this->request->columnValues, $origDozent);
    \SessionOperations::setVarValueWTIntern('newDozStatusCode', $statusCode);
    \SessionOperations::setVarValueWTIntern('newDozWrongFields', $wrongFields);

    return $this->getResponse();
  }

  protected function getResponse()
  {
    $this->response->dnr = $this->getRequestedId();
    $this->response->dguid = $this->getRequestedGuid();

    return $this->response;
  }
}

class HandleDozentUpdateRequest extends \Kufer\Web\KuferTools\Basis\UseCase\XsrfRequest
{
  public $dnr;
  public $dguid;
  public $columnValues;
  public $wssHandler;
}

class HandleDozentUpdateResponse extends \Kufer\Web\KuferTools\Basis\UseCase\ToolResponse
{
  public $dnr;
  public $dguid;
}