//
//  IMBaseRemoteInfo.swift

//
//  Created by Leon on 2025/8/18.
//

import UIKit

// 各类数据模型
enum MsgOptType: Int, Codable {
    case unknow = 0
    case upvote = 1
    case downvote = 2
    
    init(from decoder: Decoder) throws {
        let container = try decoder.singleValueContainer()
        let rawValue = try? container.decode(Int.self)
        self = MsgOptType(rawValue: rawValue ?? 0) ?? .unknow
    }
}

/**
 serverExtension 和 customAttachment的后端数据
 */
class IMBaseRemoteInfo: Codable{
    
    var cellType: SessionCellType! = .text
    /// 显示用的text
    var displayString: String?

    var type: String?
    
    /// 消息点赞或踩
    var optType : MsgOptType?
    
    /// 消息评分（在消息扩展字段）
    var score: CGFloat?
    
    /// 只在自定义消息中存在
    var customAttachment: IMCustomAttachment?

    /// 心动分值(String) in Conversation的serverExtension
    var heartbeatVal: CGFloat?
    /// 心动等级 in Conversation的serverExtension
    var heartbeatLevel: HeartbeatLevel?
    /// 关系展示开关 in Conversation serverExtension
    var isShow: Bool?

    /// 通过 SessionBaseModel 的数据，快捷获取对应的 后端数据IMBaseRemoteInfo
    static func getBaseInfo(model: SessionBaseModel) -> IMBaseRemoteInfo {
        var baseInfo: IMBaseRemoteInfo!
        if model.baseRemoteInfo != nil {
            baseInfo = model.baseRemoteInfo
        } else {
            baseInfo = IMRemoteUtil.dealRemoteInfo(message: model.v2msg)
            model.baseRemoteInfo = baseInfo
        }
        return baseInfo
    }
}


class IMYidunExtInfo: Codable {
    var ext: String?
    var priceUnitDesc: String?
    var type: String?
    var version: String?
    var taskId: String?

    var code: Int?
    var suggestion: Int?
    var status: Int?

}
