<?php

namespace App\Services;

use App\Repositories\Synonym;

class SynonymService
{
    private $synonymRepository;

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

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

        return $synonym;
    }

    public function delete($id)
    {
        $synonym = $this->synonymRepository->findOrFail($id);
        $synonym->delete();
    }

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

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

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

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