//
//  MVHotVideoModel.swift
//  MusicVideoPlus
//
//  Created by ak on 2021/6/4.
//

import Foundation
import BFFramework
let kSaveHotVideoData = "kSaveHotVideoData"
class MVHotVideoModel: NSObject {
    
    //分类 ID
    var categoryId:Int = 0
    //分类名
    var categoryName:String = ""
    //图标
    var categoryEmoji:String = ""
    //分类下所有推荐视频
    var videos:Array = Array<PQVideoListModel>.init()
    // 是否被选中
    var isSelected: Bool = false
    
    
    class func getCacheData() -> Array<MVHotVideoModel> {
        
        var hotVideos:Array = Array<MVHotVideoModel>.init()
        let svaeData =  getUserDefaults(key: kSaveHotVideoData)
        if(svaeData != nil){
            let saveArray = jsonStringToArray(jsonString:svaeData as! String)  as! [[String: Any]]
            for item in saveArray {
                
                let hotVideoModel:MVHotVideoModel = MVHotVideoModel.init()
                hotVideoModel.categoryId = item["categoryId"] as? Int ?? 0
                hotVideoModel.categoryName = item["categoryName"]  as? String ?? ""
                hotVideoModel.categoryEmoji = item["categoryEmoji"] as? String ?? ""
                let videos = item["videos"] as! [[String: Any]]
                for video in videos {
                    let tempModel = PQVideoListModel(jsonDict: video)
                    tempModel.categoryName = hotVideoModel.categoryName
                    tempModel.categoryImage = hotVideoModel.categoryEmoji
                    hotVideoModel.videos.append(tempModel)
                }
                hotVideos.append(hotVideoModel)
            }
        }
    
        return hotVideos
    }
    
   class  func saveCacheData(data:Array<Any>) {
        
        saveUserDefaults(key: kSaveHotVideoData, value: arrayToJsonString(data))
    
        
       
    }
}
