<?php

declare(strict_types=1);

namespace App\Service;

use App\Repository\TblOfertaRepository;

final class TblOfertaService
{
    private TblOfertaRepository $TblOfertaRepository;

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

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

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

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

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

        return $this->TblOfertaRepository->create($TblOferta);
    }

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

        return $this->TblOfertaRepository->update($TblOferta, $data);
    }

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