<?php

namespace App\Services;

use App\Repositories\Version;

class VersionService
{
    private $versionRepository;

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

    public function save(array $data)
    {
        if (isset($data['id'])) {
            $version = $this->versionRepository->findOrFail($data['id']);
            $version->update($data);
        } else {
            $version = $this->versionRepository->create($data);
        }

        return $version;
    }

    public function delete($id)
    {
        $version = $this->versionRepository->findOrFail($id);
        $version->delete();
    }

    public function get($id)
    {
        return $this->versionRepository->findOrFail($id);
    }

    public function getAll()
    {
        return $this->versionRepository->all();
    }

    public function with(array $children)
    {
        return $this->versionRepository->with($children)->get();
    }

    public function getOneWith($id, array $children)
    {
        return $this->versionRepository->with($children)->findOrFail($id);
    }
}
