package io.delphiplatform.api.v3.view.datahealth;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

import io.delphiplatform.api.v3.model.datahealth.DataCompleteness;
import io.delphiplatform.api.v3.model.datahealth.DataCompletenessItems;
import io.delphiplatform.api.v3.model.datahealth.DataHealthChartPosition;
import io.delphiplatform.api.v3.model.datahealth.DataHealthChartPositions;
import io.delphiplatform.api.v3.model.datahealth.DataHealthRangeReport;
import io.delphiplatform.api.v3.model.datahealth.DataHealthStatusReport;
import io.delphiplatform.api.v3.rdb.service.DataCompletenessService;
import io.delphiplatform.api.v3.rdb.service.DataHealthChartPositionService;
import io.delphiplatform.api.v3.rdb.service.DataHealthStatusAnalyticsService;
import io.delphiplatform.api.v3.rdb.service.DataHealthStatusService;
import io.delphiplatform.api.v3.view.util.Params;

@Controller
@RequestMapping("${spring.data.rest.base-path:/v3}")
public class DataHealthApiController implements DataHealthApi {

    private final DataCompletenessService dataCompletenessService;
    private final DataHealthChartPositionService dataHealthChartPositionService;
    private final DataHealthStatusService dataHealthStatusService;
    private final DataHealthStatusAnalyticsService dataHealthStatusAnalyticsService;

    @Autowired
    public DataHealthApiController(DataCompletenessService dataCompletenessService,
        DataHealthChartPositionService dataHealthChartPositionService,
        DataHealthStatusService dataHealthStatusService,
        DataHealthStatusAnalyticsService dataHealthStatusAnalyticsService) {
        this.dataCompletenessService = dataCompletenessService;
        this.dataHealthChartPositionService = dataHealthChartPositionService;
        this.dataHealthStatusService = dataHealthStatusService;
        this.dataHealthStatusAnalyticsService = dataHealthStatusAnalyticsService;
    }

    @Override
    public ResponseEntity<DataCompletenessItems> getCompletenessData() {
        List<DataCompleteness> items = dataCompletenessService.getDataCompleteness();
        return ResponseEntity.ok(new DataCompletenessItems().items(items).count(items.size()));
    }

    @Override
    public ResponseEntity<DataHealthChartPositions> getChartPositionsData(Params params) {
        List<DataHealthChartPosition> items = dataHealthChartPositionService.getDataHealthChartPositions(params);
        return ResponseEntity.ok(new DataHealthChartPositions().items(items).count(items.size()));
    }

    @Override
    public ResponseEntity<DataHealthRangeReport> getDataHealthStatusAnalytics(Params params) {
        return ResponseEntity.ok(dataHealthStatusAnalyticsService.getDataHealthRangeReport(params));
    }

    @Override
    public ResponseEntity<DataHealthStatusReport> getDataHealthStatus(Params params) {
        return ResponseEntity.ok(dataHealthStatusService.getDataHealthStatusReport(params));
    }

}
