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

namespace Kufer\KuferTools\Teilnehmer\VhsNachricht;

class SendVhsNachrichtUseCase extends \Kufer\KuferTools\Basis\UseCase\ToolUseCase
{  
  public function __construct($request)
  {
    parent::__construct($request, new SendVhsNachrichtResponse());
  }
  
  public function hasAccess($pToolSectionId = NULL)
  {
    if(!parent::hasAccess()) {
      return false;
    }
   
    else if(!$this->request->isXsrfOk && !$this->request->isRefresh) {
      return false;
    }
    return true;
  }
  
  public static function getToolId()
  {
    return TOOL_VHSNACHRICHT_TN;
  }
  
  public static function getToolSectionId()
  {
    return 315;
  }
  
  public function action()
  {
    $user = $this->getUser();
    $statusCode = \Kufer\KuferTools\Utils\SendFeedback::sendFeedback(NULL, $this->getToolId(), $this->getToolSectionId(), 
            $this->session->getCurrentWebToolsTeilnehmer(), $user, $this->request->nachricht_betreff, $this->request->nachricht_body, $this->request->isRefresh);
    
    return $this->getResponse($statusCode, $user);
  }
  
  protected function getResponse($pStatusCode, $pUser)
  {
    $this->handleResponseStrategies();
    $this->response->statusCode = $pStatusCode;
    $this->response->user = $pUser;
    return $this->response;
  }
  
  protected function getResponseStrategies()
  {
    return array(
        new \Kufer\KuferTools\Utils\ResponseStrategies\ResponseMitRahmen($this)
    );
  }
  
}

class SendVhsNachrichtRequest
{
  public $nachricht_betreff;
  public $nachricht_body;
  public $isRefresh;
  public $isXsrfOk;
}

class SendVhsNachrichtResponse extends \Kufer\KuferTools\Basis\UseCase\ToolResponse
{
  public $statusCode;
  public $menuPunkte;
  public $user;
}