package com.example.uitugasakhir.model
import com.google.gson.annotations.SerializedName
import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.*
import androidx.room.Database
import androidx.room.RoomDatabase
import android.content.Context
import androidx.room.Room



object DatabaseInstance {

    fun get(context: Context): AppDatabase {
        return Room.databaseBuilder(
            context,
            AppDatabase::class.java,
            "app_db"
        ).build()
    }
}

@Entity(tableName = "riwayat")
data class RiwayatEntity(
    @PrimaryKey(autoGenerate = true)
    val id: Int = 0,
    val waktu: String,
    val aksi: String,
    val keterangan: String,
    val jeda: Int,
    val status: String,
    val mode: String
)

@Dao
interface RiwayatDao {

    @Query("SELECT * FROM riwayat ORDER BY id DESC")
    suspend fun getAll(): List<RiwayatEntity>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertAll(list: List<RiwayatEntity>)

    @Insert
    suspend fun insert(item: RiwayatEntity)

    @Query("DELETE FROM riwayat")
    suspend fun clear()
}

@Database(
    entities = [RiwayatEntity::class],
    version = 1
)
abstract class AppDatabase : RoomDatabase() {
    abstract fun riwayatDao(): RiwayatDao
}



data class RiwayatItem(
    val id: Int,
    val waktu: String,
    val aksi: String,
    val keterangan: String,
    val status: String,
    val jeda: Int,
    val mode: String
)

data class Sensor(
    @SerializedName("kelembapan_udara")
    val kelembaban_udara: Float,

    @SerializedName("suhu_udara")
    val suhu_udara: Float,

    @SerializedName("kelembapan_tanah")
    val kelembaban_tanah: Float,

    @SerializedName("intensitas_hujan")
    val intensitas_hujan: Float,
)

// jadwal
data class JadwalItem(
    val id: String,
    val waktu: String,
    val status: String
)

data class ResponseMessage(
    val success: Boolean,
    val message: String
)

data class SettingResponse(
    val status: String,
    val message: String? = null,
    val kelembapan_tanah: Int = 0,
    val suhu_udara: Int = 0,
    val kelembapan_udara: Int = 0
)

data class Setting(
    val kelembapan_tanah: Int,
    val suhu_udara: Int,
    val kelembapan_udara: Int
)

data class AmbangBatas(
    val min_tanah: Int,
    val min_suhu: Int,
    val min_udara: Int,
    val max_tanah: Int,
    val max_suhu: Int,
    val max_udara: Int,
    val critical_tanah: Int
)

// buzzer + led dan ui sinkron
data class WarningResponse(
    val id: Int,
    val status_warning: Int,
    val status_buzzer: Int,
    val status_led: Int,
    val acknowledged: Int,
    val pesan: String
)

//notifikasi
data class WarningItem(
    val id: Int,
    val status: String,
    val message: String,
    val time: Long,
    val mode: String
)

data class JedaResponse(
    val success: Boolean,
    val message: String?,
    val data: JedaData?
)

data class JedaData(
    val id: String? = null,
    val jeda: String? = null
)

// set pompa
data class ApiResponse(
    val status: String,
    val pump: String? = null,
    val message: String? = null
)

data class UnreadResponse(
    val status: String,
    val total: Int
)