//
//  MPPositive_CustomPlayListModel.swift
//  relax.offline.mp3.music
//
//  Created by Mr.Zhou on 2024/6/20.
//

import UIKit
import CoreData

@objc(MPPositive_CustomPlayListModel)
///自定义歌单列表
class MPPositive_CustomPlayListModel: NSManagedObject, MP_CoreDataManageableDelegate, MP_CoreDataOperationDelegate {
    typealias ManagedObject = MPPositive_CustomPlayListModel
    ///歌单ID（创建时生成，具备唯一性）, 以年月日时分秒生成
    @NSManaged var playListId:String!
    ///歌单标题（用户输入，可更改）
    @NSManaged var title:String!
    ///创建时间（创建时生成）
    @NSManaged var createTime:Date!
    ///歌曲信息组
    @NSManaged var videos:NSSet!
    
}
extension MPPositive_CustomPlayListModel {
    ///将videos转为[MPPositive_CustomVideoModel]
    var videosArray:[MPPositive_CustomVideoModel]{
        let set = videos as? Set<MPPositive_CustomVideoModel> ?? []
        //转化成数组模型并进行排序（根据添加时间决定顺序）
        let array = Array(set).sorted { item1, item2 in
            return item1.addTime > item2.addTime
        }
        return array
    }
    ///[MPPositive_CustomVideoModel]转为videos并设置给videos
    func addToRelationshipToCustomVideos(_ values:[MPPositive_CustomVideoModel]) {
        //转为集合
        let set = NSSet(array: values)
        //设置videos等于这个集合
        self.videos = set
    }
}
 
