package com.crm.chat.data.model

// Chat Provider Models
data class ChatProvider(
    val id: Long,
    val name: String,
    val type: ChatProviderType,
    val status: ChatProviderStatus,
    val transport: ChatProviderTransport
)

enum class ChatProviderType {
    TWILIO, FACEBOOK_MESSENGER, WAZZUP
}

enum class ChatProviderStatus {
    ACTIVE, INACTIVE
}

enum class ChatProviderTransport {
    SMS, WHATSAPP, MESSENGER
}

// Chat Models
data class Chat(
    val id: Long,
    val title: String? = null,
    val type: String, // Using String instead of enum to match API
    val providerId: Long,
    val createdBy: Long? = null,
    val externalId: String? = null,
    val entityId: Long? = null,
    val createdAt: String? = null,
    val users: List<ChatUserItem>? = null,
    val pinnedMessages: List<Long>? = null,
    val lastMessage: ChatMessage? = null,
    val unseenCount: Int = 0,
    val updatedAt: String? = null,
    val hasAccess: Boolean = true
)

// Additional chat-related models
data class ChatUserItem(
    val id: Long,
    val userId: Long,
    val role: String,
    val name: String? = null,
    val externalUser: ChatUserExternal? = null
)

enum class ChatType {
    PERSONAL, GROUP, EXTERNAL
}

// Chat Message Models
data class ChatMessage(
    val id: Long,
    val chatId: Long,
    val chatUserId: Long,
    val text: String,
    val statuses: List<ChatMessageStatusItem>? = null,
    val files: List<ChatMessageFile>? = null,
    val replyTo: ChatMessage? = null, // Changed from Long to ChatMessage object
    val reactions: List<ChatMessageReaction>? = null,
    val createdAt: String
)

// Additional message-related models
data class ChatMessageStatusItem(
    val chatUserId: Long,
    val status: String, // "sent", "delivered", "seen", etc.
    val createdAt: String
)

data class ChatMessageFile(
    val id: Long,
    val fileId: String,
    val fileName: String,
    val fileSize: Long? = null,
    val fileType: String? = null,
    val downloadUrl: String,
    val createdAt: String
)

data class ChatMessageReaction(
    val id: Long,
    val chatUserId: Long,
    val reaction: String,
    val createdAt: String
)

enum class ChatMessageStatus {
    SENT, DELIVERED, READ, FAILED
}

enum class ChatMessageType {
    TEXT, IMAGE, FILE, AUDIO
}

// API Response Models
data class ChatsResponse(
    val chats: List<Chat>,
    val totalCount: Int
)

data class ChatMessagesResponse(
    val messages: List<ChatMessage>,
    val totalCount: Int,
    val hasMore: Boolean
)

data class SendMessageRequest(
    val text: String,
    val messageType: String = "text",
    val fileUrl: String? = null,
    val replyToId: Long? = null,
    val fileIds: List<String>? = null
)

// File Upload Models
data class FileUploadResponse(
    val key: String,
    val id: String,
    val fileName: String,
    val fileSize: Long,
    val mimeType: String,
    val createdAt: String,
    val downloadUrl: String
)

data class FileUploadListResponse(
    val files: List<FileUploadResponse>
)

// WebSocket Event Models
data class ChatEvent(
    val type: String,
    val chatId: Long,
    val data: Any
)

data class NewMessageEvent(
    val message: ChatMessage
)
