76 lines
1.9 KiB
Swift
76 lines
1.9 KiB
Swift
import Foundation
|
|
|
|
// MARK: - Message Type
|
|
|
|
/// Backend-aligned message type enum.
|
|
/// Raw values match the backend's MESSAGE_TYPES snake_case strings exactly.
|
|
public enum MessageType: String, Codable, Hashable, Sendable {
|
|
case text = "text"
|
|
case system = "system"
|
|
case rateCard = "rate_card"
|
|
case availabilityWidget = "availability_widget"
|
|
case bookingProposal = "booking_proposal"
|
|
case counterOffer = "counter_offer"
|
|
case agreementSummary = "agreement_summary"
|
|
case screeningRequest = "screening_request"
|
|
case autoResponse = "auto_response"
|
|
case paymentRequest = "payment_request"
|
|
}
|
|
|
|
// MARK: - Message Status
|
|
|
|
public enum MessageStatus: String, Codable, Hashable, Sendable {
|
|
case sending
|
|
case sent
|
|
case delivered
|
|
case read
|
|
case failed
|
|
}
|
|
|
|
// MARK: - Message
|
|
|
|
public struct Message: Codable, Identifiable, Hashable, Sendable {
|
|
public let id: String
|
|
public let threadId: String
|
|
public let senderId: String
|
|
public let content: String?
|
|
public let richContent: RawJSON?
|
|
public let type: MessageType
|
|
public var status: MessageStatus
|
|
public let createdAt: Date
|
|
public let updatedAt: Date
|
|
|
|
public init(
|
|
id: String,
|
|
threadId: String,
|
|
senderId: String,
|
|
content: String?,
|
|
richContent: RawJSON?,
|
|
type: MessageType,
|
|
status: MessageStatus,
|
|
createdAt: Date,
|
|
updatedAt: Date
|
|
) {
|
|
self.id = id
|
|
self.threadId = threadId
|
|
self.senderId = senderId
|
|
self.content = content
|
|
self.richContent = richContent
|
|
self.type = type
|
|
self.status = status
|
|
self.createdAt = createdAt
|
|
self.updatedAt = updatedAt
|
|
}
|
|
|
|
public var isRichCard: Bool {
|
|
type != .text && type != .system && richContent != nil
|
|
}
|
|
|
|
public var isSystem: Bool {
|
|
type == .system
|
|
}
|
|
|
|
public var displayText: String {
|
|
content ?? ""
|
|
}
|
|
}
|