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

import edu.prlab.tyler.iotgateway.cloud.pojo.device.Device;
import edu.prlab.tyler.iotgateway.gateway.repositories.DeviceIndexRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class DeviceService {

    private DeviceIndexRepository deviceIndexRepository;
    private RemoteService remoteService;

    @Autowired
    public DeviceService(DeviceIndexRepository deviceIndexRepository, RemoteService remoteService) {
        this.deviceIndexRepository = deviceIndexRepository;
        this.remoteService = remoteService;
    }

    //TODO bind and read from blockchain
    public Optional<Device> bindDeviceAndGateway(String udn) {
        return remoteService.readDevice(udn);
    }

    public Optional<Iterable<Device>> readDevices() {
        return remoteService.readDevices();
    }

}