<?php

namespace App\Services;

use App\Repositories\Accreditation;

class AccreditationService
{
    private $accreditationRepository;

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

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

        return $accreditation;
    }

    public function delete($id)
    {
        $accreditation = $this->accreditationRepository->findOrFail($id);
        $accreditation->delete();
    }

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

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

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

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