package com.design.mischiefgo.entity

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class DuplicateRepository(private val infoDao: DuplicateDao){
    // 获取所有点赞项
    fun getAllLike():List<Duplicate> = infoDao.getAllLike()
    suspend fun getAll(): List<Duplicate> = infoDao.selectAll()

    // 获取所有自定义项
    fun getAllCustomization(): List<Duplicate> = infoDao.getAllCustomization()

    // 获取高效随机数据
    suspend fun getMoreEfficient(): List<Duplicate> = withContext(Dispatchers.IO) {
        infoDao.getMoreEfficient()
    }

    // 检查点赞存在性
    suspend fun checkLikeExists(name: String): Boolean = withContext(Dispatchers.IO) {
        infoDao.checkLikeExists(name)
    }

    // 检查名称存在性
    suspend fun checkNameExists(name: String): Boolean = withContext(Dispatchers.IO) {
        infoDao.checkNameExists(name)
    }

    // 添加点赞
    suspend fun updateLikeStatus(name: String, isLike: Boolean) = withContext(Dispatchers.IO) {
        infoDao.updateLikeStatus(name, isLike)
    }
    // 移除点赞
    suspend fun removeLike(name: String) = withContext(Dispatchers.IO) {
        infoDao.removeLike(name)
    }

    // 插入单个项目
    suspend fun insert(duplicate: Duplicate): Long = withContext(Dispatchers.IO) {
        infoDao.insert(duplicate)
    }

    // 删除项目
    suspend fun delete(duplicate: Duplicate): Int = withContext(Dispatchers.IO) {
        infoDao.delete(duplicate)
    }
}