<?php

namespace App\Modules\History\Application\Insert;

use App\Modules\Admin\Domain\IdAdmin;
use App\Modules\History\Domain\History;
use App\Modules\History\Domain\HistoryDate;
use App\Modules\History\Domain\HistoryOperation;
use App\Modules\History\Domain\HistoryRepository;
use App\Modules\History\Domain\HistoryValueNew;
use App\Modules\History\Domain\HistoryValueOld;
use App\Modules\History\Domain\IdHistory;
use App\Modules\History\Domain\IdHistoryRecord;
use App\Modules\History\Domain\IdHistoryReference;
use App\Modules\HistoryTable\Domain\IdHistoryTable;
use App\Modules\Shared\Domain\Bus\Event\EventBus;

final class HistoryInserter
{
    public function __construct(
        private HistoryRepository $repository,
        private EventBus $eventBus
    ) {}

    public function __invoke(
        IdHistory $id,
        HistoryDate $date,
        HistoryValueOld $valueOld,
        HistoryValueNew $valueNew,
        HistoryOperation $operation,
        IdHistoryRecord $idRecord,
        IdHistoryReference $idReference,
        IdHistoryTable $idHistoryTable,
        IdAdmin $idAdmin,
    ) {
        $model = new History(
            $id,
            $date,
            $valueOld,
            $valueNew,
            $operation,
            $idRecord,
            $idReference,
            $idHistoryTable,
            $idAdmin
        );
        $id = $this->repository->insert($model);
        return $id->value();
    }
}
