<?php

declare(strict_types=1);

namespace App\Service;

use App\Repository\TblPreguntaRepository;

final class TblPreguntaService
{
    private TblPreguntaRepository $TblPreguntaRepository;

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

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

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

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

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

        return $this->TblPreguntaRepository->create($TblPregunta);
    }

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

        return $this->TblPreguntaRepository->update($TblPregunta, $data);
    }

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