<?php
// Dealers.php
// Copyright P.Kassel, M.Seliger, G.Trietsch, all Rights Reserved
namespace Docuform\Api\Server;use Docuform\Api\HttpRequestHandler;use Docuform\Api\UserType;use Psr\Http\Message\ResponseInterface;use Psr\Http\Message\ServerRequestInterface;use Docuform\Api\ApiScopes;class Dealers extends HttpRequestHandler{public function getAllowedUserTypes($request):array{return[UserType::USERTYPE_DEALER,UserType::USERTYPE_ADMIN];}public function getRequiredScopes($request):array{if($request->getMethod()!=='GET')return['allOf'=>[ApiScopes::server_read,ApiScopes::server_write],'anyOf'=>[]];else return['allOf'=>[],'anyOf'=>[ApiScopes::server_read,ApiScopes::mcs]];}public function handleRequest($request,& $response,$arguments):int{$result=404;if($request->getMethod()==='GET'){if(empty($arguments)){$dealers=Dealer::readAll($this->getContainer());if(is_array($dealers)&&!empty($dealers)){Dealer::buildJsonResponse($response,$dealers,'dealers');$result=200;}else{$result=204;}}else{$serverApi=$this->getContainer()->get('RestApi');$dealer=$serverApi->getDealer();if($dealer!==false&&$dealer->id>0){Dealer::buildJsonResponse($response,$dealer,'dealer');$result=200;}}}return $result;}}