<?php

namespace App\Modules\HtlCampSchedule\Application\UpdateLock;

use App\Modules\HtlCampSchedule\Application\Index\HtlCampScheduleIndexer;
use App\Modules\HtlCampSchedule\Domain\IdHtlCampSchedule;
use App\Modules\HtlCampSchedule\Domain\HtlCampScheduleLock;
use App\Modules\Shared\Domain\Bus\Command\CommandHandler;

final class UpdateLockHtlCampScheduleHandler implements CommandHandler
{
    public function __construct(
        private HtlCampScheduleLockUpdater $lockUpdater,
        private HtlCampScheduleIndexer $indexer
    ) {}

    public function __invoke(UpdateLockHtlCampScheduleCommand $command)
    {
        $index = $this->indexer->__invoke(new IdHtlCampSchedule($command->id()), true);
        $index->setLock(new HtlCampScheduleLock($command->lock()));
        $this->lockUpdater->__invoke($index);
    }
}
