//
//  ScenicQueueSocketModels.swift
//  suixinkan
//

import Foundation

/// 排队 WebSocket 消息。
struct ScenicQueueSocketMessage: Decodable, Equatable {
    let code: Int
    let data: ScenicQueueSocketData?

    /// 是否为排队更新事件。
    var isQueueEvent: Bool {
        data?.action == ScenicQueueSocketAction.queueUpdated.rawValue
            || data?.action == ScenicQueueSocketAction.ticketCalled.rawValue
    }
}

/// 排队 WebSocket data 节点。
struct ScenicQueueSocketData: Decodable, Equatable {
    let action: String
    let params: ScenicQueueSocketParams?
}

/// 排队 WebSocket params 节点。
struct ScenicQueueSocketParams: Decodable, Equatable {
    let scenicSpotId: Int64?
    let recordId: Int64?
    let operatorUid: Int64?
    let eventId: String?

    enum CodingKeys: String, CodingKey {
        case scenicSpotId = "scenic_spot_id"
        case recordId = "record_id"
        case operatorUid = "operator_uid"
        case eventId = "event_id"
    }
}

/// 排队 WebSocket action。
enum ScenicQueueSocketAction: String {
    case queueUpdated = "scenic_spot_queue_updated"
    case ticketCalled = "scenic_queue_ticket_called"
}
