package com.aksenov.monitor.services;

import com.aksenov.monitor.data.Customer;
import com.aksenov.monitor.data.Monitor;
import com.aksenov.monitor.repositories.MonitorRepository;

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 MonitorService {

    private final MonitorRepository repository;

    public MonitorService(MonitorRepository repository) {
        this.repository = repository;
    }

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

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

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

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

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

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

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

}
