package com.example.palmguardapp.data.repository

import com.example.palmguardapp.data.local.entity.DiseaseDiagnose
import com.example.palmguardapp.data.local.room.DiseaseDiagnoseDao
import kotlinx.coroutines.flow.Flow

class DiseaseRepository private constructor(
    private val diseaseDiagnoseDao: DiseaseDiagnoseDao
) {
    suspend fun insert(diseaseDiagnose: DiseaseDiagnose) {
        diseaseDiagnoseDao.insert(diseaseDiagnose)
    }

    suspend fun update(diseaseDiagnose: DiseaseDiagnose) {
        diseaseDiagnoseDao.update(diseaseDiagnose)
    }

    suspend fun delete(diseaseDiagnose: DiseaseDiagnose) {
        diseaseDiagnoseDao.delete(diseaseDiagnose)
    }

    fun getAllDisease(): Flow<List<DiseaseDiagnose>> = diseaseDiagnoseDao.getAllDisease()

    fun getDiseaseById(id: String): Flow<DiseaseDiagnose> = diseaseDiagnoseDao.getDiseaseById(id)


    companion object {
        @Volatile
        private var instance: DiseaseRepository? = null

        fun getInstance(diseaseDiagnoseDao: DiseaseDiagnoseDao): DiseaseRepository =
            instance ?: synchronized(this) {
                instance ?: DiseaseRepository(diseaseDiagnoseDao).also { instance = it }
            }
    }
}