<?php

namespace App\Services;

use App\Repositories\Checklist;

class ChecklistService
{
    private $checklistRepository;

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

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

        return $checklist;
    }

    public function delete($id)
    {
        $checklist = $this->checklistRepository->findOrFail($id);
        $checklist->delete();
    }

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

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

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

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