package com.aksenov.monitor.services;

import com.aksenov.monitor.data.Manufacturer;
import com.aksenov.monitor.repositories.ManufacturerRepository;

import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

@Service
public class ManufacturerService {

    private final ManufacturerRepository repository;

    public ManufacturerService(ManufacturerRepository repository) {
        this.repository = repository;
    }

    public Optional<Manufacturer> get(Long id) {
        return repository.findById(id);
    }

    public Manufacturer save(Manufacturer entity) {
        return repository.save(entity);
    }

    public void delete(Long id) {
        repository.deleteById(id);
    }

    public Page<Manufacturer> list(Pageable pageable) {
        return repository.findAll(pageable);
    }

    public Page<Manufacturer> list(Pageable pageable, Specification<Manufacturer> filter) {
        return repository.findAll(filter, pageable);
    }

    public List<Manufacturer> list() {
        return repository.findAll();
    }

    public int count() {
        return (int) repository.count();
    }

}
