package edu.prlab.tyler.iotgateway.cloud.services;


import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyPolicyReport;
import edu.prlab.tyler.iotgateway.cloud.repositories.PrivacyPolicyReportRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class PrivacyPolicyReportService extends CrudService<PrivacyPolicyReport, String> {

    private DeviceService deviceService;
    private PrivacyPolicyReportRepository repository;

    @Autowired
    public PrivacyPolicyReportService(PrivacyPolicyReportRepository repository,
                                      DeviceService deviceService) {
        super(repository);
        this.repository = repository;
        this.deviceService = deviceService;
    }

    public Optional<PrivacyPolicyReport> readByDevice(String udn) {
        return deviceService.readByUDN(udn)
                .flatMap(repository::findByDevice);
    }

}
