package com.syaroful.agrilinkvocpro.core.utils.extention

import com.syaroful.agrilinkvocpro.data.model.DhtWithHour
import com.syaroful.agrilinkvocpro.data.model.NpkWithHour
import java.text.SimpleDateFormat
import java.util.Date

fun getValuesForSensorNpk(sensor: String, data: List<NpkWithHour>): List<Double> {
    return when (sensor) {
        "Nitrogen" -> data.mapNotNull { it.soilNitrogen?.toDouble() }
        "Pospor" -> data.mapNotNull { it.soilPhosphorus?.toDouble() }
        "Kalium" -> data.mapNotNull { it.soilPotassium?.toDouble() }
        "Suhu Tanah" -> data.mapNotNull { it.soilTemperature?.toDouble() }
        "PH Tanah" -> data.mapNotNull { it.soilPh?.toDouble() }
        "Kelembapan" -> data.mapNotNull { it.soilHumidity?.toDouble() }
        "Konduktivitas" -> data.mapNotNull { it.soilConductivity?.toDouble() }
        else -> emptyList()
    }
}

fun getValuesForSensorDht(sensor: String, data: List<DhtWithHour>): List<Double> {
    return when (sensor) {
        "Kelembaban Udara" -> data.mapNotNull { it.viciHumidity?.toDouble() }
        "Suhu Ruang" -> data.mapNotNull { it.viciTemperature?.toDouble() }
        "Intensitas Cahaya" -> data.mapNotNull { it.viciLuminosity?.toDouble() }
        else -> emptyList()
    }
}

fun getCurrentDate(): String {
    val sdf = SimpleDateFormat("dd MMMM yyyy", java.util.Locale.getDefault())
    return sdf.format(Date())
}