package com.syaroful.agrilinkvocpro.data.repository

import com.syaroful.agrilinkvocpro.data.model.DhtGraphicDataResponse
import com.syaroful.agrilinkvocpro.data.model.NpkGraphicDataResponse
import com.syaroful.agrilinkvocpro.data.model.SensorDataResponse
import com.syaroful.agrilinkvocpro.data.network.ApiService
import retrofit2.Response

class SensorDataRepository(private val apiService: ApiService) {
    private var _latestSensorData: SensorDataResponse? = null
    val latestSensorData: SensorDataResponse?
        get() = _latestSensorData

    suspend fun getLatestSensorData(authHeader: String): Response<SensorDataResponse> {
        val response = apiService.getLatestSensorData(authHeader)
        if (response.isSuccessful) {
            _latestSensorData = response.body()
        }
        return response
    }

    suspend fun getNpkDataSensor(
        authHeader: String,
        startDate: String,
        endDate: String,
        timeRange: String = "HOURLY",
        sensor: String
    ): Response<NpkGraphicDataResponse> {
        return apiService.getNpkDataSensor(authHeader, startDate, endDate, timeRange, sensor)
    }

    suspend fun getDhtDataSensor(
        authHeader: String,
        startDate: String,
        endDate: String,
        timeRange: String = "HOURLY",
        sensor: String
    ): Response<DhtGraphicDataResponse> {
        return apiService.getDhtDataSensor(authHeader, startDate, endDate, timeRange, sensor)
    }
}