//
//  MPPositive_CustomPlayListViewModel.swift
//  relax.offline.mp3.music
//
//  Created by Mr.Zhou on 2024/6/24.
//

import UIKit
///自定义歌单ViewModel
class MPPositive_CustomPlayListViewModel: NSObject {
    ///排序值
    var index:Int!
    ///封面图
    var coverImageURL:URL!
    ///标题
    var title:String!
    ///副标题（歌曲数量）
    var subTitle:String!
    ///自定义歌单
    var playList:MPPositive_CustomPlayListModel
    
    init(_ list:MPPositive_CustomPlayListModel) {
        self.playList = list
        super.init()
        configure()
    }
    //配置ViewModel
    private func configure() {
        //取歌单最后一首歌曲封面作为歌单封面
        if let first = playList.videosArray.first {
            coverImageURL = first.coverImageURL
        }
        //标题
        title = playList.title
        //副标题为歌曲数量
        subTitle = "\(playList.videosArray.count) songs"
    }
    //设置预览图
    func setImage(_ imageView:UIImageView) {
        if coverImageURL != nil {
            imageView.kf.setImage(with: coverImageURL, placeholder: placeholderImage)
        }else {
            imageView.image = placeholderImage
        }
    }
}
