<?php

namespace App\Services;

use App\Repositories\FilterItemsAssociation;

class FilterItemsAssociationService
{
    private $filteritemsassociationRepository;

    public function __construct(FilterItemsAssociation $filteritemsassociationRepository)
    {
        $this->filteritemsassociationRepository = $filteritemsassociationRepository;
    }

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

        return $filteritemsassociation;
    }

    public function delete($id)
    {
        $filteritemsassociation = $this->filteritemsassociationRepository->findOrFail($id);
        $filteritemsassociation->delete();
    }

    public function deleteAllWithFilterItemId($id)
    {
        return $this->filteritemsassociationRepository->where('filter_item_id', $id)->delete();
    }

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

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

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

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