//
//  MPPositive_LoadSearchResultsViewModel.swift
//  MusicPlayer
//
//  Created by Mr.Zhou on 2024/5/13.
//

import UIKit
///搜索结果数据管理模型
class MPPositive_SearchResultsLoadViewModel: NSObject {
    ///模块组
    var sectionLists:[MPPositive_SearchResultListViewModel]!{
        didSet{
            DispatchQueue.main.async {
                [weak self] in
                guard let self = self else {return}
                //得到了搜索结果
                if resultReloadBlock != nil {
                    resultReloadBlock!()
                }
            }
        }
    }
    var resultReloadBlock:(() -> Void)?
    //用户输入的搜索文本
    init(_ text:String){
        super.init()
        getSearchResults(text)
    }
    //根据用户输入文本内容请求搜索接口
    private func getSearchResults(_ text:String) {
        MP_NetWorkManager.shared.requestSearchPreviewResults(text) { [weak self] results in
            self?.sectionLists = results
        }
    }
}
