<?php

namespace App\Modules\DefinedService\OfficesBriefing\Application\List;

use App\Modules\DefinedService\OfficesBriefing\Application\OfficesBriefingResponse;
use App\Modules\DefinedService\OfficesBriefing\Application\OfficesBriefingResponses;
use App\Modules\DefinedService\OfficesBriefing\Domain\BriefingOfficeName;
use App\Modules\Shared\Domain\Bus\Query\QueryHandler;

final class ListOfficesBriefingQueryHandler implements QueryHandler
{
    public function __construct(private OfficesBriefingLister $lister) {}

    public function __invoke(ListOfficesBriefingQuery $query): OfficesBriefingResponses
    {
        return new OfficesBriefingResponses(...array_map(
            fn($index) => new OfficesBriefingResponse(
                $index->id()->value(),
                $index->date()->value(),
                $index->dateUpdate()->value(),
                $index->name()->value(),
                $index->status()->value(),
                $index->color()->value(),
                $index->capacity()->value(),
                $index->idParentOffice()?->value(),
                $index->idLocation()->value(),
            ),
            $this->lister->__invoke(new BriefingOfficeName($query->name()), $query->action())
        ));
    }
}
