//
//  historyManager.swift
//  WallpaperHD_Live


import Foundation

class ImageNameManager {
    
    // UserDefaults 键
    private let key = "imageNames"
    
    // 获取图片名数组
    func getImageNames() -> [String] {
        return UserDefaults.standard.stringArray(forKey: key) ?? []
    }
    
    // 添加新的图片名
    func addImageName(_ imageName: String) {
        var imageNames = getImageNames()
        
        // 判断是否已经存在相同的图片名
        if !imageNames.contains(imageName) {
            // 如果不存在，则添加到数组
            imageNames.append(imageName)
            // 存储更新后的数组回 UserDefaults
            UserDefaults.standard.set(imageNames, forKey: key)
            print("Added new image name: \(imageName)")
        } else {
            print("Image name already exists: \(imageName)")
        }
    }
    
    // 删除图片名
    func removeImageName(_ imageName: String) {
        var imageNames = getImageNames()
        
        // 删除指定的图片名
        if let index = imageNames.firstIndex(of: imageName) {
            imageNames.remove(at: index)
            // 存储更新后的数组回 UserDefaults
            UserDefaults.standard.set(imageNames, forKey: key)
            print("Removed image name: \(imageName)")
        } else {
            print("Image name not found: \(imageName)")
        }
    }
}
