package com.gallery.free.wallpaper.database

import android.content.Context

class FavorWpManager private constructor(context: Context) {

    private val dbHelper = FavorWpDbHelper(context)

    companion object {
        @Volatile
        private var INSTANCE: FavorWpManager? = null

        fun getInstance(context: Context): FavorWpManager {
            return INSTANCE ?: synchronized(this) {
                val instance = FavorWpManager(context)
                INSTANCE = instance
                instance
            }
        }
    }

    // 添加收藏，包含描述
    fun addFavorite(imageUrl: String, description: String = ""): Boolean {
        return dbHelper.addFavorite(imageUrl, description)
    }

    // 更新收藏描述
    fun updateFavoriteDescription(imageUrl: String, description: String): Boolean {
        return dbHelper.updateFavoriteDescription(imageUrl, description)
    }

    // 添加或更新收藏（如果存在则更新描述）
    fun addOrUpdateFavorite(imageUrl: String, description: String = ""): Boolean {
        return if (isFavorite(imageUrl)) {
            updateFavoriteDescription(imageUrl, description)
        } else {
            addFavorite(imageUrl, description)
        }
    }

    fun removeFavorite(imageUrl: String): Boolean {
        return dbHelper.removeFavorite(imageUrl)
    }

    fun isFavorite(imageUrl: String): Boolean {
        return dbHelper.isFavorite(imageUrl)
    }

    // 获取所有收藏的URL（向后兼容）
    fun getAllFavorites(): List<String> {
        return dbHelper.getAllFavorites()
    }

    // 获取所有收藏的详细信息
    fun getAllFavoritesWithInfo(): List<FavorWpDbHelper.FavoriteInfo> {
        return dbHelper.getAllFavoritesWithInfo()
    }

    fun getFavoriteCount(): Int {
        return dbHelper.getFavoriteCount()
    }
}