<?php

declare(strict_types=1);

namespace App\Service;

use App\Repository\TblSegmentoRepository;

final class TblSegmentoService
{
    private TblSegmentoRepository $TblSegmentoRepository;

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

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

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

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

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

        return $this->TblSegmentoRepository->create($TblSegmento);
    }

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

        return $this->TblSegmentoRepository->update($TblSegmento, $data);
    }

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