//
//  LNRoomUserMessageItem.swift
//  Gami
//
//  Created by OneeChan on 2026/3/12.
//

import Foundation
import AtomicXCore


enum LNRoomMessageItemType {
    case chat
    case system
}

let LNRoomChatMessageTypeKey = "type"
enum LNRoomChatMessageType: String, CaseIterable {
    case chat = "0"
}


class LNRoomUserMessage {
    let innerMessage: Barrage
    let type: LNRoomChatMessageType
    
    var messageItems: [LNRoomMessageItem]? {
        var list: [LNRoomMessageItem] = []
        switch type {
        case .chat:
            let item = LNRoomChatMessageItem()
            item.sender = innerMessage.sender.userID
            item.avatar = innerMessage.sender.avatarURL
            item.nickname = innerMessage.sender.userName
            item.content = innerMessage.textContent
            list.append(item)
        }
        
        return list
    }
    
    init?(info: Barrage) {
        guard info.messageType == .text else {
            return nil
        }
        guard let value = info.extensionInfo?[LNRoomChatMessageTypeKey],
              let subType = LNRoomChatMessageType(rawValue: value) else {
            return nil
        }
        
        type = subType
        innerMessage = info
    }
}
