<?php

declare(strict_types=1);

namespace App\Service;

use App\Repository\TblRepresentanteRepository;

final class TblRepresentanteService
{
    private TblRepresentanteRepository $TblRepresentanteRepository;

    public function __construct(TblRepresentanteRepository $TblRepresentanteRepository)
    {
        $this->TblRepresentanteRepository = $TblRepresentanteRepository;
    }

    public function checkAndGet(int $TblRepresentanteId): object
    {
        return $this->TblRepresentanteRepository->checkAndGet($TblRepresentanteId);
    }

    public function getAll(): array
    {
        return $this->TblRepresentanteRepository->getAll();
    }

    public function getOne(int $TblRepresentanteId): object
    {
        return $this->checkAndGet($TblRepresentanteId);
    }

    public function create(array $input): object
    {
        $TblRepresentante = json_decode((string) json_encode($input), false);

        return $this->TblRepresentanteRepository->create($TblRepresentante);
    }

    public function update(array $input, int $TblRepresentanteId): object
    {
        $TblRepresentante = $this->checkAndGet($TblRepresentanteId);
        $data = json_decode((string) json_encode($input), false);

        return $this->TblRepresentanteRepository->update($TblRepresentante, $data);
    }

    public function delete(int $TblRepresentanteId): void
    {
        $this->checkAndGet($TblRepresentanteId);
        $this->TblRepresentanteRepository->delete($TblRepresentanteId);
    }
}
