package app.closer.data.repository

import app.closer.data.local.CategoryDao
import app.closer.data.local.QuestionDao
import app.closer.data.local.mapper.toQuestion
import app.closer.data.local.mapper.toQuestionCategory
import app.closer.domain.model.Question
import app.closer.domain.model.QuestionCategory
import app.closer.domain.repository.QuestionRepository
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class RoomQuestionRepository @Inject constructor(
    private val questionDao: QuestionDao,
    private val categoryDao: CategoryDao
) : QuestionRepository {
    override suspend fun getDailyQuestion(): Question? {
        return questionDao.getDailyQuestion()?.toQuestion()
    }

    override suspend fun getQuestionById(id: String): Question? {
        return questionDao.getQuestionById(id)?.toQuestion()
    }

    override suspend fun getQuestionsByCategory(categoryId: String): List<Question> {
        return questionDao.getQuestionsByCategory(categoryId).map { it.toQuestion() }
    }

    override suspend fun getCategories(): List<QuestionCategory> {
        return categoryDao.getAllCategories().map { it.toQuestionCategory() }
    }

    override suspend fun getCategoryById(id: String): QuestionCategory? {
        return categoryDao.getCategoryById(id)?.toQuestionCategory()
    }

    override suspend fun getQuestionCountByCategory(categoryId: String): Int {
        return questionDao.getQuestionCountByCategory(categoryId)
    }

    override suspend fun getQuestionsByType(type: String): List<Question> {
        return questionDao.getQuestionsByType(type).map { it.toQuestion() }
    }

    override suspend fun getQuestionsForPrediction(): List<Question> {
        return questionDao.getQuestionsForPrediction().map { it.toQuestion() }
    }

    override suspend fun getDesireSyncQuestions(sex: String): List<Question> {
        return questionDao.getDesireSyncQuestions(sex).map { it.toQuestion() }
    }
}
