package com.example.uitugasakhir.api

import com.example.uitugasakhir.model.SensorResponse
import okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.Response
import retrofit2.http.*
import com.example.uitugasakhir.model.RiwayatItem
import com.example.uitugasakhir.model.Sensor
import com.example.uitugasakhir.model.SettingResponse
import com.example.uitugasakhir.model.AmbangBatas

// jadwal
import com.example.uitugasakhir.model.JadwalItem
import com.example.uitugasakhir.model.ResponseMessage

// Jeda
import com.example.uitugasakhir.model.UnreadResponse
import com.example.uitugasakhir.model.JedaResponse

import com.example.uitugasakhir.model.WarningItem
import com.example.uitugasakhir.model.ApiResponse

import com.example.uitugasakhir.model.WarningResponse

interface ApiService {

    @FormUrlEncoded
    @POST("forgot_password.php")
    fun forgotPassword(
        @Field("email") email: String
    ): Call<ResponseBody>

    @GET("get_setting.php")
    suspend fun getSetting(
        @Query("user_id") userId: Int
    ): Response<SettingResponse>

    @FormUrlEncoded
    @POST("save_setting.php")
    suspend fun saveSetting(
        @Field("user_id") userId: Int,
        @Field("kelembapan_tanah") tanah: Int,
        @Field("suhu_udara") suhu: Int,
        @Field("kelembapan_udara") udara: Int
    ): Response<SettingResponse>

    @GET("config.php")
    suspend fun setConfig(
        @Query("jadwal") jadwal: String,
        @Query("ambang") ambang: Int,
        @Query("jeda") jeda: Int
    ): String

    @GET("get_riwayat.php")
    suspend fun getRiwayat(
        @Query("user_id") userId: Int
    ): List<RiwayatItem>

    @FormUrlEncoded
    @POST("save_riwayat.php")
    suspend fun saveRiwayat(
        @Field("aksi") aksi: String,
        @Field("status") status: String,
        @Field("keterangan") keterangan: String
    ): Response<ApiResponse>

    @GET("get_sensor.php")
    suspend fun getSensor(): SensorResponse

    @GET("setting_notifikasi.php")
    suspend fun getSettingFromApi(): SettingResponse

    @GET("get_ambang_batas.php")
    suspend fun getAmbangBatas(): AmbangBatas

    @FormUrlEncoded
    @POST("save_log.php")
    suspend fun saveLog(
        @Field("jenis") jenis: String,
        @Field("kategori") kategori: String,
        @Field("pesan") pesan: String,
        @Field("level") level: String,
        @Field("nilai_sensor") nilai: String?,
        @Field("min_batas") min: String?,
        @Field("max_batas") max: String?
    ): okhttp3.ResponseBody

    @FormUrlEncoded
    @POST("delete_log.php")
    suspend fun deleteLog(
        @Field("id") id: Int
    ): Response<ResponseBody>

    @GET("get_log.php")
    suspend fun getLogs(): List<WarningItem>


    // jadwal
    @GET("get_jadwal.php")
    suspend fun getJadwal(): List<JadwalItem>

    // TAMBAH jadwal
    @FormUrlEncoded
    @POST("tambah_jadwal.php")
    suspend fun tambahJadwal(
        @Field("waktu") waktu: String,
        @Field("status_waktu") status: String
    ): ResponseMessage

    // HAPUS jadwal
    @FormUrlEncoded
    @POST("delete_jadwal.php")
    suspend fun deleteJadwal(
        @Field("id") id: Int
    ): ResponseMessage

    // Jeda
    // GET jeda
    @GET("get_jeda.php")
    suspend fun getJeda(): Response<JedaResponse>

    // UPDATE jeda
    @FormUrlEncoded
    @POST("set_jeda.php")
    suspend fun setJeda(
        @Field("jeda") jeda: String
    ): Response<JedaResponse>

    // setting pompa
    @FormUrlEncoded
    @POST("set_pump.php")
    suspend fun setPump(
        @Field("status") status: String,
        @Field("mode") mode: String
    ): Response<ApiResponse>

    @GET("get_unread_count.php")
    suspend fun getUnreadCount(): UnreadResponse

    @FormUrlEncoded
    @POST("read_notification.php")
    suspend fun readNotification(
        @Field("id") id: Int
    ): ResponseBody

    @POST("read_all_notifications.php")
    suspend fun readAllNotifications(): ResponseBody

    @GET("get_warning.php")
    suspend fun getWarning(): WarningResponse

    @GET("acknowledge_warning.php")
    suspend fun acknowledgeWarning(): Response<Unit>

    @FormUrlEncoded
    @POST("insert_warning.php")
    suspend fun insertWarning(

        @Field("pesan") pesan: String

    ): Response<Unit>

}