<?php

namespace App\Services;

use App\Repositories\ManagementLink;

class ManagementLinkService
{
    private $managementLinkRepository;

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

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

        return $management_links;
    }

    public function delete($id)
    {
        $management_links = $this->managementLinkRepository->findOrFail($id);
        $management_links->delete();
    }

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

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

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

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