<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

namespace Kufer\KuferTools\Allgemein\PersoenlicheDaten\PersoenlicheDaten;

abstract class PersoenlicheDatenUseCase extends \Kufer\KuferTools\Basis\UseCase\ToolUseCase
{
  public function __construct($request)
  {
    parent::__construct($request, new PersoenlicheDatenResponse());
  }

  public static function getToolId()
  {
    return 13;
  }

  abstract protected function isBearbeitbar();

  abstract protected function getPerson($user);

  public function action()
  {
    $user = $this->getUser();


    return $this->getResponse($user);
  }

  protected function getResponse($user)
  {
    $this->handleResponseStrategies();
    if ($this->request->changedPerson) {
      $this->response->person = $this->request->changedPerson;
    } else {
      $this->response->person = $this->getPerson($user);
    }
    $this->response->origPerson = $this->getPerson($user);
    $this->response->statusCode = $this->request->statusCode;

    if ($this->toolSettings->showFreeField && trim($this->toolSettings->freeField) != '') {
      $this->response->freeField = $this->toolSettings->freeField;
    }

    $this->response->wrongFields = $this->request->wrongFields;
    $this->response->passwort = $this->request->passwort;
    $this->response->bearbeitbar = $this->isBearbeitbar();
    $tool0Settings = $this->toolSettingsApi->getToolSettings(0);
    $this->response->emailAendernErfordertPwEingabe = $tool0Settings->emailAendernErfordertPwEingabe;

    return $this->response;
  }

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

class PersoenlicheDatenRequest
{
  public $statusCode;
  public $changedPerson;
  public $wrongFields;
  public $passwort = '';
}

class PersoenlicheDatenResponse extends \Kufer\KuferTools\Basis\UseCase\ToolResponse
{
  public $user;
  public $menuPunkte = array();
  public $person;
  public $origPerson;
  public $statusCode;
  public $freeField = '';
  public $bearbeitbar = false;
  public $wrongFields;
  public $passwort = '';
  public $emailAendernErfordertPwEingabe = false;
}