//
//  PQReCreateModel.swift
//  PQSpeed
//
//  Created by SanW on 2020/12/28.
//  Copyright © 2020 BytesFlow. All rights reserved.
//

import RealmSwift
import UIKit
import BFCommonKit

public class PQReCreateModel: Object {
    @objc dynamic public var canReproduce: Int = 0 // 是否可以被再创作，1：是，0：否
    @objc dynamic public var draftboxId: String? // 草稿ID
    @objc dynamic public var parentProjectId: String? // 父项目ID
    @objc dynamic public var rootProjectId: String? // 根项目ID
    @objc dynamic public var projectId: String? // 项目ID
    @objc dynamic public var projectLinkUrl: String? // 项目链接
    @objc dynamic public var reProduceCount: Int = 0 // 被再创作次数
    @objc dynamic public var reProduceVideoFlag: Int = 0 //  再创作视频标记，1：是，0：否
    @objc dynamic public var videoId: String? // 视频id
    @objc dynamic public var parentVideoId: String? // 父视频id
    @objc dynamic public var rootVideoId: String? // 根视频id
    @objc dynamic public var rhythmMusicFlag: Int = 0 // 是否有卡点音乐标记 1：是，0：否
    @objc dynamic public var rhythmMusicName: String? // 卡点音乐歌名
    var rhythmMusicNameWidth: CGFloat = 0 // 卡点音乐显示宽度
    
    // add by ak 卡点模式（1：跳跃卡点，2：快慢速，3：仅配乐）
    @objc dynamic public var rhythmMode:Int = 0
    override required init() {
        super.init()
    }

    init(jsonDict: [String: Any]) {
        super.init()
        if jsonDict.keys.contains("canReproduce") {
            canReproduce = Int("\(jsonDict["canReproduce"] ?? "0")") ?? 0
        }
        if jsonDict.keys.contains("draftboxId"), "\(jsonDict["draftboxId"] ?? "")" != "<null>" {
            draftboxId = "\(jsonDict["draftboxId"] ?? "")"
        }
        if jsonDict.keys.contains("parentProjectId"), "\(jsonDict["parentProjectId"] ?? "")" != "<null>" {
            parentProjectId = "\(jsonDict["parentProjectId"] ?? "")"
        }
        if jsonDict.keys.contains("rootProjectId"), "\(jsonDict["rootProjectId"] ?? "")" != "<null>" {
            rootProjectId = "\(jsonDict["rootProjectId"] ?? "")"
        }
        if jsonDict.keys.contains("projectId"), "\(jsonDict["projectId"] ?? "")" != "<null>" {
            projectId = "\(jsonDict["projectId"] ?? "")"
        }
        if jsonDict.keys.contains("projectLinkUrl") {
            projectLinkUrl = "\(jsonDict["projectLinkUrl"] ?? "")"
        }
        if jsonDict.keys.contains("reProduceCount") {
            reProduceCount = Int("\(jsonDict["reProduceCount"] ?? "0")") ?? 0
        }
        if jsonDict.keys.contains("reProduceVideoFlag") {
            reProduceVideoFlag = Int("\(jsonDict["reProduceVideoFlag"] ?? "0")") ?? 0
        }
        
        if jsonDict.keys.contains("rhythmMode"){
            rhythmMode = Int("\(jsonDict["rhythmMode"] ?? "0")") ?? 0
        }
        if jsonDict.keys.contains("parentVideoId"), "\(jsonDict["parentVideoId"] ?? "")" != "<null>" {
            parentVideoId = "\(jsonDict["parentVideoId"] ?? "")"
        }
        if jsonDict.keys.contains("rhythmMusicFlag") {
            rhythmMusicFlag = Int("\(jsonDict["rhythmMusicFlag"] ?? "0")") ?? 0
        }
        if jsonDict.keys.contains("rhythmMusicName"), "\(jsonDict["rhythmMusicName"] ?? "")" != "<null>" {
            rhythmMusicName = "\(jsonDict["rhythmMusicName"] ?? "")"
            if rhythmMusicFlag == 1 {
                rhythmMusicNameWidth = sizeWithText(text: rhythmMusicName ?? "", font: UIFont.systemFont(ofSize: 13), size: CGSize(width: cScreenWidth - cDefaultMargin * 10 - 32 - 40, height: cDefaultMargin * 3)).width
                if rhythmMusicNameWidth < cDefaultMargin * 4 {
                    rhythmMusicNameWidth = cDefaultMargin * 4
                }
                rhythmMusicNameWidth = rhythmMusicNameWidth + 32 + 40
            }
        }
    }
}
