package com.syaroful.agrilinkvocpro.control_feature.data.repository

import com.syaroful.agrilinkvocpro.control_feature.data.model.ActuatorHistoryResponse
import com.syaroful.agrilinkvocpro.control_feature.data.model.ActuatorStatusResponse
import com.syaroful.agrilinkvocpro.control_feature.data.model.ControlLogResponse
import com.syaroful.agrilinkvocpro.control_feature.data.network.ControlService
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody.Companion.toRequestBody
import retrofit2.Response

class ControlRepository(
    private val controlService: ControlService
) {

    suspend fun controlWaterValve(
        authHeader: String,
        action: String
    ): Response<ControlLogResponse> {
        val actionPart = action.toRequestBody("text/plain".toMediaTypeOrNull())
        return controlService.controlWaterValve(authHeader, actionPart)
    }

    suspend fun controlNutrientValve(
        authHeader: String,
        action: String
    ): Response<ControlLogResponse> {
        val actionPart = action.toRequestBody("text/plain".toMediaTypeOrNull())
        return controlService.controlNutrientValve(authHeader, actionPart)
    }

    suspend fun controlPump(authHeader: String, action: String): Response<ControlLogResponse> {
        val actionPart = action.toRequestBody("text/plain".toMediaTypeOrNull())
        return controlService.controlPump(authHeader, actionPart)
    }

    suspend fun getActuatorStatus(authHeader: String): Response<ActuatorStatusResponse> {
        return controlService.getActuatorStatus(authHeader)
    }

    suspend fun getActuatorHistory(authHeader: String): Response<ActuatorHistoryResponse> {
        return controlService.getActuatorsControlLog(authHeader)
    }

}