local this = {}

function this:init()
  this.super.init(self)
  self.data = {
    conversationList = {},
    shieldList = {},
    meetingConversation = require(L_R.store .. "chat.data.conversation").new(),
    meetingSwitchLineRecord = {},
    emojiOwnedDic = {},
    emojiCollectedList = {}
  }
end

function this:getConversationList()
  return self.data.conversationList
end

function this:getShieldList()
  return self.data.shieldList
end

function this:getMeetingConversation()
  return self.data.meetingConversation
end

function this:getMeetingSwitchLineRecord()
  local res = {}
  for i, v in pairs(self.data.meetingSwitchLineRecord) do
    table.insert(res, {
      time = i,
      mapId = v.mapId,
      lineId = v.lineId
    })
  end
  table.sort(res, function(a, b)
    return a.time < b.time
  end)
  return res
end

function this:getEmojiOwnedDic()
  return self.data.emojiOwnedDic
end

function this:getEmojiCollectedList()
  return self.data.emojiCollectedList
end

function this:getConversation(playerUid, isCreate)
  local conversationList = self:getConversationList()
  local entity = conversationList[playerUid]
  if entity == nil and isCreate then
    entity = require(L_R.store .. "chat.data.conversation").new()
    conversationList[playerUid] = entity
    entity.playerUid = playerUid
  end
  return entity
end

function this:getPlayerUid(conversation)
  return conversation.playerUid
end

function this:getUnreadMessageNum(conversation)
  return conversation.num
end

function this:getUpgradeTime(conversation)
  return conversation.upgrade
end

function this:getMessageList(conversation)
  return conversation.chats
end

function this:getIsQeqChatInfo(conversation)
  return conversation.hasReqChat
end

function this:getMessageMsg(message)
  return message.msg
end

function this:getMessageContent(message)
  if message.type == L_Const.ChatInfoType.CHAT_NORMAL then
    return message.msg
  elseif message.type == L_Const.ChatInfoType.CHAT_COMMON then
    local chatQuickTpl = L_GameTpl:getChatQuickTpl()
    local tpl = chatQuickTpl:getTplById(tonumber(message.msg))
    return chatQuickTpl:getWords(tpl)
  elseif message.type == L_Const.ChatInfoType.CHAT_EMOJI then
    local chatEmojiTpl = L_GameTpl:getChatEmojiTpl()
    local tpl = chatEmojiTpl:getTplById(tonumber(message.msg))
    return chatEmojiTpl:getIcon(tpl)
  end
end

function this:getMessageTime(message)
  return message.time
end

function this:getMessageType(message)
  return message.type
end

function this:getIsMessageSendByMyself(message)
  return message.player_id == L_PlayerStore:getPlayerId()
end

function this:getMessageSender(message)
  return message.player_id
end

function this:getIsMessageFromMeeting(message)
  return message.isMeeting
end

function this:getIsShieldChat(uid)
  return self.data.shieldList[uid] ~= nil
end

function this:getAllUnReadNum()
  local conversation = self:getConversationList()
  local res = 0
  for i, v in pairs(conversation) do
    res = res + self:getUnreadMessageNum(v)
  end
  return res
end

return this
