package com.syaroful.agrilinkvocpro.data.network

import com.syaroful.agrilinkvocpro.data.model.DhtGraphicDataResponse
import com.syaroful.agrilinkvocpro.data.model.LoginResponse
import com.syaroful.agrilinkvocpro.data.model.NpkGraphicDataResponse
import com.syaroful.agrilinkvocpro.data.model.RegisterResponse
import com.syaroful.agrilinkvocpro.data.model.SensorDataResponse
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.POST
import retrofit2.http.Query


data class LoginRequest(
    val username: String,
    val password: String,
    val remember_me: Boolean = true
)

data class RegisterRequest(
    val username: String,
    val password: String,
    val email: String,
    val fullname: String
)

interface ApiService {
    @POST("auth/login")
    suspend fun login(
        @Header("Authorization") authHeader: String,
        @Body body: LoginRequest,
    ): Response<LoginResponse>

    @POST("auth/register")
    suspend fun register(
        @Body body: RegisterRequest,
    ): Response<RegisterResponse>

    @GET("api/sensor-readings/latest")
    suspend fun getLatestSensorData(
        @Header("Authorization") authHeader: String
    ): Response<SensorDataResponse>

    @GET("api/sensor-readings/search")
    suspend fun getNpkDataSensor(
        @Header("Authorization") authHeader: String,
        @Query("range[start]") startDate: String,
        @Query("range[end]") endDate: String,
        @Query("range[time_range]") timeRange: String = "HOURLY",
        @Query("sensor") sensor: String
    ): Response<NpkGraphicDataResponse>

    @GET("api/sensor-readings/search")
    suspend fun getDhtDataSensor(
        @Header("Authorization") authHeader: String,
        @Query("range[start]") startDate: String,
        @Query("range[end]") endDate: String,
        @Query("range[time_range]") timeRange: String = "HOURLY",
        @Query("sensor") sensor: String
    ): Response<DhtGraphicDataResponse>

}