package com.rdkr.tide_display.backend.firmware.service;

import com.rdkr.tide_display.backend.gcp.Firmware;
import com.rdkr.tide_display.backend.gcp.StorageService;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class FirmwareServiceImpl implements FirmwareService {

  private final StorageService storageService;

  @Override
  public List<Firmware> getFirmwareVersions() {
    return storageService.getFirmwareVersions();
  }

  @Override
  public Firmware getLatestFirmwareVersion() {
    return storageService.getFirmwareVersions().getFirst();
  }

  @Override
  public Optional<Firmware> getFirmwareVersion(String version) {
    return
        storageService.getFirmwareVersions().stream()
            .filter(firmware -> firmware.getVersion().equals(version))
            .findFirst();
  }
}
