2026-09-14 19:26:26 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Uwil\ArcadiaApiPhpClient\Service;
|
|
|
|
|
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Error\ApiError;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\Employee;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\PageOf;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiSorter\EmployeeSorter;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiValueObject\ArcadiaEmployeeId;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiValueObject\SiteId;
|
2026-09-15 12:49:19 +02:00
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\Pagination\PageSize;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\Pagination\Pagination;
|
2026-09-14 19:26:26 +02:00
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\Pagination\StreamOf;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Repository\EmployeeRepository;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @internal
|
|
|
|
|
*/
|
|
|
|
|
final class ArcadiaEmployeeService implements EmployeeService
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
|
|
|
|
private readonly EmployeeRepository $employeeRepository
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @return StreamOf<Employee> */
|
|
|
|
|
public function streamAll(
|
|
|
|
|
PageSize $pageSize = new PageSize(),
|
|
|
|
|
?EmployeeSorter $sorter = null,
|
|
|
|
|
): StreamOf {
|
|
|
|
|
return new StreamOf(
|
|
|
|
|
fn (Pagination $pagination) => $this->getAll($pagination, $sorter),
|
|
|
|
|
$pageSize,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @return StreamOf<Employee> */
|
|
|
|
|
public function streamAllSince(
|
|
|
|
|
\DateTimeInterface $since,
|
|
|
|
|
PageSize $pageSize = new PageSize(),
|
|
|
|
|
\SortDirection $sortDirection = \SortDirection::Descending,
|
|
|
|
|
): StreamOf {
|
|
|
|
|
return new StreamOf(
|
|
|
|
|
fn (Pagination $pagination) => $this->getAllSince($pagination, $since, $sortDirection),
|
|
|
|
|
$pageSize,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param SiteId[]|SiteId $sites
|
|
|
|
|
* @return StreamOf<Employee>
|
|
|
|
|
*/
|
|
|
|
|
public function streamAllOfSitesSince(
|
|
|
|
|
array | SiteId $sites,
|
|
|
|
|
\DateTimeInterface $since,
|
|
|
|
|
PageSize $pageSize = new PageSize(),
|
|
|
|
|
\SortDirection $sortDirection = \SortDirection::Descending,
|
|
|
|
|
): StreamOf {
|
|
|
|
|
return new StreamOf(
|
|
|
|
|
fn (Pagination $pagination) => $this->getAllOfSitesSince($pagination, $sites, $since, $sortDirection),
|
|
|
|
|
$pageSize,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param SiteId[]|SiteId $sites
|
|
|
|
|
* @return StreamOf<Employee>
|
|
|
|
|
*/
|
|
|
|
|
public function streamAllOfSites(
|
|
|
|
|
array | SiteId $sites,
|
|
|
|
|
PageSize $pageSize = new PageSize(),
|
|
|
|
|
?EmployeeSorter $sorter = null,
|
|
|
|
|
): StreamOf {
|
|
|
|
|
return new StreamOf(
|
|
|
|
|
fn (Pagination $pagination) => $this->getAllOfSites($pagination, $sites, $sorter),
|
|
|
|
|
$pageSize,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @return PageOf<Employee>|ApiError */
|
|
|
|
|
public function getAllSince(
|
|
|
|
|
Pagination $pagination,
|
|
|
|
|
\DateTimeInterface $since,
|
|
|
|
|
\SortDirection $sortDirection = \SortDirection::Descending,
|
|
|
|
|
): PageOf | ApiError {
|
|
|
|
|
return $this->employeeRepository->selectAllSince(
|
|
|
|
|
$pagination,
|
|
|
|
|
$since,
|
|
|
|
|
$sortDirection
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @return PageOf<Employee>|ApiError */
|
|
|
|
|
public function getAll(
|
|
|
|
|
Pagination $pagination,
|
|
|
|
|
?EmployeeSorter $sorter = null,
|
|
|
|
|
): PageOf | ApiError {
|
|
|
|
|
return $this->employeeRepository->selectAll(
|
|
|
|
|
$pagination,
|
|
|
|
|
$sorter,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param SiteId[]|SiteId $sites
|
|
|
|
|
* @return PageOf<Employee>|ApiError
|
|
|
|
|
*/
|
|
|
|
|
public function getAllOfSitesSince(
|
|
|
|
|
Pagination $pagination,
|
|
|
|
|
array | SiteId $sites,
|
|
|
|
|
\DateTimeInterface $since,
|
|
|
|
|
\SortDirection $sortDirection = \SortDirection::Descending,
|
|
|
|
|
): PageOf | ApiError {
|
|
|
|
|
$sites = is_array($sites) ? $sites : [$sites];
|
|
|
|
|
|
|
|
|
|
if (count($sites) < 1) {
|
|
|
|
|
throw new \InvalidArgumentException('At least 1 site is required');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($sites as $site) {
|
|
|
|
|
if (! ($site instanceof SiteId)) {
|
|
|
|
|
throw new \InvalidArgumentException('Expected instance of ' . SiteId::class);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->employeeRepository->selectAllHavingSitesSince(
|
|
|
|
|
$pagination,
|
|
|
|
|
$since,
|
|
|
|
|
$sites,
|
|
|
|
|
$sortDirection,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param SiteId[]|SiteId $sites
|
|
|
|
|
* @return PageOf<Employee>|ApiError
|
|
|
|
|
*/
|
|
|
|
|
public function getAllOfSites(
|
|
|
|
|
Pagination $pagination,
|
|
|
|
|
array | SiteId $sites,
|
|
|
|
|
?EmployeeSorter $sorter = null,
|
|
|
|
|
): PageOf | ApiError {
|
|
|
|
|
$sites = is_array($sites) ? $sites : [$sites];
|
|
|
|
|
|
|
|
|
|
if (count($sites) < 1) {
|
|
|
|
|
throw new \InvalidArgumentException('At least 1 site is required');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($sites as $site) {
|
|
|
|
|
if (! ($site instanceof SiteId)) {
|
|
|
|
|
throw new \InvalidArgumentException('Expected instance of ' . SiteId::class);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($sorter !== null) {
|
|
|
|
|
return $this->employeeRepository->selectAllHavingSites(
|
|
|
|
|
$pagination,
|
|
|
|
|
$sites,
|
|
|
|
|
$sorter
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->employeeRepository->selectAllHavingSites(
|
|
|
|
|
$pagination,
|
|
|
|
|
$sites,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function findBy(ArcadiaEmployeeId $id): Employee | null | ApiError
|
|
|
|
|
{
|
|
|
|
|
return $this->employeeRepository->find($id);
|
|
|
|
|
}
|
|
|
|
|
}
|