//
//  TSRingDownVM.swift
//  AIRingtone
//
//  Created by 100Years on 2025/3/18.
//
import ObjectMapper

class TSRingDownVM {

    lazy var modelList: [TSAIRintoneHistoryModel] = {
        getModelList()
    }()
    
    private func getModelList()->[TSAIRintoneHistoryModel]{
        var list = [TSAIRintoneHistoryModel]()
        
        if aiRintoneHistoryModel.list.count > 0 {
            list.append(aiRintoneHistoryModel)
        }

        return list
    }
    
    //保存的历史
    lazy var aiRintoneHistoryModel: TSAIRintoneHistoryModel = {
        let model = TSAIRintoneHistoryModel(title: "Generate History", list:TSMineRintoneHistory.listModelArray)
        return model
    }()
    
}

extension TSRingDownVM {
    
    func updateRecentData() {
        aiRintoneHistoryModel.list = TSMineRintoneHistory.listModelArray
        modelList = getModelList()
    }
    
    func removeModel(model:TSRingModel){
        TSMineRintoneHistory.removeModel(model: model)
        updateRecentData()
        
        if let pathURL = TSCommonTool.getCachedURLString(from: model.audioUrl) {
            TSFileManagerTool.removeItem(from: pathURL)
        }

    }
    
}
