<?php

namespace App\Services;

use App\Repositories\Filter;

class FilterService
{
    private $filterRepository;

    public function __construct(Filter $filterRepository)
    {
        $this->filterRepository = $filterRepository;
    }

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

        return $filter;
    }

    public function delete($id)
    {
        $filter = $this->filterRepository->findOrFail($id);
        $filter->delete();
    }

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

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

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

    public function withCount(array $children)
    {
        return $this->filterRepository->withCount($children)->get();
    }

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