<?php

declare(strict_types=1);

namespace App\Service;

use App\Repository\AccionRepository;

final class AccionService
{
    private AccionRepository $AccionRepository;

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

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

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

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

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

        return $this->AccionRepository->create($Accion);
    }

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

        return $this->AccionRepository->update($Accion, $data);
    }

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