//
//  MPPositive_LoadMusicModel.swift
//  MusicPlayer
//
//  Created by Mr.Zhou on 2024/4/25.
//

import UIKit
///b面音乐数据管理load
class MPPositive_BrowseLoadViewModel: NSObject {
    static let shared = MPPositive_BrowseLoadViewModel()
    ///预览模块数据组(通过网络请求刷新)
    var browseModuleLists:[MPPositive_BrowseModuleListViewModel] = []
    override init() {
        super.init()
        //当网络请求工具触发browse请求闭包时
        MP_NetWorkManager.shared.browseRequestStateBlock = {
            [weak self] (lists,isCompleted) in
            guard let self = self else {return}
            //配置预览模块数据
            browseModuleLists.append(contentsOf: lists)
            //移除为空的数据
            browseModuleLists = browseModuleLists.filter{($0.items.count != 0)}
            //通知首页刷新UI
            NotificationCenter.notificationKey.post(notificationName: .positive_browses_reload)
        }
    }
    ///刷新预览数据
    func reloadBrowseLists() {
        //清空预览模块数据
        browseModuleLists.removeAll()
        //调用网络请求工具的预览请求
        MP_NetWorkManager.shared.requestBrowseDatas()
    }
}
