2026-09-14 19:26:20 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-09-16 10:30:17 +02:00
|
|
|
namespace Uwil\ArcadiaApiPhpClient\Mapper;
|
2026-09-14 19:26:20 +02:00
|
|
|
|
|
|
|
|
use Microsoft\Kiota\Abstractions\Types\Date;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\Employee;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\PageOf;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\PaginationDto;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiValueObject\ArcadiaEmployeeId;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiValueObject\EstablishmentCode;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiValueObject\ServiceId;
|
|
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiValueObject\SiteId;
|
2026-09-15 12:49:15 +02:00
|
|
|
use Uwil\ArcadiaApiPhpClient\Lib\Pagination\Pagination;
|
2026-09-14 19:26:20 +02:00
|
|
|
use Uwil\ArcadiaKiotaOpenApiClient\Models\Employee as KiotaEmployee;
|
|
|
|
|
use Uwil\ArcadiaKiotaOpenApiClient\Models\EmployeeListResponse;
|
|
|
|
|
use Uwil\ArcadiaKiotaOpenApiClient\Models\PaginationMeta;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @internal
|
|
|
|
|
*/
|
2026-09-16 10:30:17 +02:00
|
|
|
final class EmployeeMapper
|
2026-09-14 19:26:20 +02:00
|
|
|
{
|
|
|
|
|
public function toDto(KiotaEmployee $model): Employee
|
|
|
|
|
{
|
|
|
|
|
$matricule = $model->getMatricule() ?? '';
|
|
|
|
|
$establishment = $model->getEstablishment() ?? '';
|
|
|
|
|
$site = $model->getSite() ?? '';
|
|
|
|
|
$service = $model->getService() ?? '';
|
|
|
|
|
|
|
|
|
|
$startDate = $this->dateToDateTime($model->getStartDate()) ?? new \DateTimeImmutable('today');
|
|
|
|
|
$createdAt = $model->getCreatedAt() ?? new \DateTimeImmutable();
|
|
|
|
|
|
|
|
|
|
return new Employee(
|
|
|
|
|
matriculePublique: new ArcadiaEmployeeId($matricule),
|
|
|
|
|
lastname: $model->getLastName() ?? '',
|
|
|
|
|
firstname: $model->getFirstName() ?? '',
|
|
|
|
|
start_date: $startDate,
|
|
|
|
|
end_date: $this->dateToDateTime($model->getEndDate()),
|
|
|
|
|
planned_end_date: $this->dateToDateTime($model->getPlannedEndDate()),
|
|
|
|
|
establishment: new EstablishmentCode($establishment),
|
|
|
|
|
site: new SiteId($site),
|
|
|
|
|
service: new ServiceId($service),
|
|
|
|
|
created_at: $createdAt,
|
|
|
|
|
updated_at: $model->getUpdatedAt(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return PageOf<Employee>
|
|
|
|
|
*/
|
|
|
|
|
public function toPage(EmployeeListResponse $response, Pagination $pagination): PageOf
|
|
|
|
|
{
|
|
|
|
|
$items = [];
|
|
|
|
|
foreach ($response->getEmployees() ?? [] as $employeeModel) {
|
|
|
|
|
$items[] = $this->toDto($employeeModel);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-16 10:30:17 +02:00
|
|
|
$paginationDto = $this->paginationDto(
|
|
|
|
|
$response->getPagination(),
|
|
|
|
|
$pagination
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return new PageOf(
|
|
|
|
|
$paginationDto,
|
|
|
|
|
$items
|
|
|
|
|
);
|
2026-09-14 19:26:20 +02:00
|
|
|
}
|
|
|
|
|
|
2026-09-16 10:30:17 +02:00
|
|
|
private function paginationDto(?PaginationMeta $meta, Pagination $pagination): PaginationDto
|
2026-09-14 19:26:20 +02:00
|
|
|
{
|
|
|
|
|
return new PaginationDto(
|
|
|
|
|
page: $meta?->getPage() ?? $pagination->pageNumber(),
|
|
|
|
|
pageSize: $meta?->getPageSize() ?? $pagination->pageSize(),
|
|
|
|
|
totalItems: $meta?->getTotalItems() ?? 0,
|
|
|
|
|
totalPages: $meta?->getTotalPages() ?? 0,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function dateToDateTime(?Date $date): ?\DateTimeInterface
|
|
|
|
|
{
|
|
|
|
|
if ($date === null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new \DateTimeImmutable((string) $date);
|
|
|
|
|
}
|
|
|
|
|
}
|