/*
 Copyright (c) 2020 Swift Models Generated from JSON powered by http://www.json4swift.com

 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 For support, please feel free to contact me at https://www.linkedin.com/in/syedabsar

 */

// 这个是一个项目所有段的数据，进入到编辑界面的时候传的这个就是这个 MODLE ， 合成和预览都是
/* XXXXX

 注意：使用 ObjectMappers 的 toJSON 函数来生成 JSON 字符串只在 Realm 的写事务中有效（write transaction）。这是因为 ObjectMapper 在解析和生成时在映射函数（ <-< code=""> ）中使用  inout 作为标记（ flag ）。Realm 会检测到标记并且强制要求 toJSON 函数只能在一个写的事务中调用，即使这个对象并没有被修改。
 参考：
 https://github.com/jakenberg/ObjectMapper-Realm
 https://github.com/alibaba/handyjson
 https://juejin.cn/post/6844903450308771847
 https://juejin.cn/post/6844904117442215944

 */

import Foundation
import ObjectMapper
import RealmSwift
import BFCommonKit

public class PQEditProjectModel: PQEditBaseModel {
    // 大 JSON 结构化数据
    @objc dynamic public var sData: PQEditSdataModel?
    @objc dynamic public var isSelected: Bool = false // 是否选中
    @objc public var coverUrl: String? // 图片
    @objc dynamic public var dataVersionCode: Int = 0 // 数据版本号
    public var cacheDataVersionCode: Int = -1 // 缓存版本号
    @objc public var draftboxId: String = "" // 草稿id
    @objc dynamic public var projectId: String = "" // 项目id
    @objc dynamic public var title: String = "" // 标题
    @objc dynamic public var updateTimestamp: Int = 0 { // 更新时间
        didSet {
            updateTimestampDes = timeIntervalToDateString(timeInterval: TimeInterval(updateTimestamp / 1000))
        }
    }

    public var updateTimestampDes: String? // 更新时间描述
    @objc public var duration: Float64 = 0 { // 时长
        didSet {
            durationDes = duration.formatDurationToHMS()
        }
    }

    public var durationDes: String = "00:00" // 时长描述
    required convenience public  init?(map _: Map) {
        self.init()
    }

    required public init() {
        super.init()
        sData = PQEditSdataModel()
    }

    public override static func primaryKey() -> String? {
        return "draftboxId"
    }

    public  override func mapping(map: Map) {
        sData <- map["sData"]
        coverUrl <- map["coverUrl"]
        dataVersionCode <- map["dataVersionCode"]
        draftboxId <- map["draftboxId"]
        projectId <- map["projectId"]
        title <- map["title"]
        updateTimestamp <- map["updateTimestamp"]
        duration <- (map["duration"], timeTransform)
        durationDes <- map["durationDes"]
        updateTimestampDes <- map["updateTimestampDes"]
    }
}
