//
//  MPPositive_RecommendLoadViewModel.swift
//  MusicPlayer
//
//  Created by Mr.Zhou on 2024/5/20.
//

import UIKit
///相关内容
class MPPositive_RecommendLoadViewModel: NSObject {
    ///相关内容组
    var sectionLists:[MPPositive_RecommendListViewModel]!{
        didSet{
            DispatchQueue.main.async {
                [weak self] in
                guard let self = self else {return}
                //得到了搜索结果
                if resultReloadBlock != nil {
                    resultReloadBlock!()
                }
            }
        }
    }
    //艺术家们
    var members:MPPositive_RecommendListViewModel!
    var resultReloadBlock:(() -> Void)?
    /// 初始化方法
    /// - Parameter browseId: 相关内容Id
    init(_ browseId:String) {
        super.init()
        //进行网络请求
        getRecommendResults(browseId)
    }
    //根据browseId进行网络请求
    private func getRecommendResults(_ text:String) {
        MP_NetWorkManager.shared.requestRecommend(text) { [weak self] results in
            self?.members = (results.filter { item in
                return item.items.first?.browseItem.pageType == "MUSIC_PAGE_TYPE_ARTIST"
            }).first
            self?.sectionLists = results.filter { item in
                return item.items.first?.browseItem.pageType != "MUSIC_PAGE_TYPE_ARTIST"
            }
        }
    }
}
