//
//  MPPositive_ArtistContentListViewModel.swift
//  MusicPlayer
//
//  Created by Mr.Zhou on 2024/5/15.
//

import UIKit

class MPPositive_ArtistContentListViewModel: NSObject {
    ///模块标题
    var title:String?
    ///模块内容组
    var itemViews:[MPPositive_BrowseItemViewModel] = []{
        didSet{
            print("用户加载\(title ?? "")的新内容")
            if completionBlock != nil {
                completionBlock!()
            }
        }
    }
    ///查询更多内容需要的id
    var browseId:String?
    ///查询更多内容需要的编码
    var params:String?
    ///当前分页信息
    var continuation:String?
    ///当前分页键值
    var itct:String?
    ///请求完成
    var completionBlock:(() -> Void)?
    
    init(_ title: String?, itemViews: [MPPositive_BrowseItemViewModel], browseId: String?, params:String?) {
        super.init()
        self.title = title
        self.itemViews = itemViews
        self.browseId = browseId
        self.params = params
    }
    
    ///请求艺术家分类详情信息
    func requestArtistType() {
        //检索是否存在moreActionId和moreActionParams
        guard let id = self.browseId, let params = params else {
            print("当前\(title ?? "")已是全部内容")
            return
        }
        //清空数据（原始数据为初始预览）
        itemViews = []
        //调用艺术家更多接口补全信息
        MP_NetWorkManager.shared.requestArtistMore(id, params: params) { [weak self] (items, continuation, itct) in
            guard let self = self else {return}
            //对内容模块组进行追加
            itemViews.append(contentsOf: items)
            self.continuation = continuation
            self.itct = itct
        }
    }
    ///继续请求艺术家分类详情信息
    func requestArtistContinuation() {
        guard let continuation = self.continuation, let itct = self.itct else {
            //没有更多了
            return
        }
        MP_NetWorkManager.shared.requestArtistMoreContinuation(continuation, itct: itct) { [weak self] (items, continuation, itct) in
            guard let self = self else {return}
            //对内容模块组进行追加
            itemViews.append(contentsOf: items)
            self.continuation = continuation
            self.itct = itct
        }
    }
}
