local this = class("announcementData")

function this:ctor()
  self.meta = nil
  self.order_id = 0
  self.announvementTab = nil
  self.end_time = 0
  self.id = 0
  self.announcementType = nil
  self.jumpId = nil
  self.hide = false
  self.publish_time = 0
  self.showPosition = 0
  self.cacheTimeOut = true
end

function this:populate(data)
  self.publish_time = data.publish_time
  self.order_id = data.order_id
  self.id = data.id
  self.announvementTab = data.tab_id
  self.end_time = data.end_time
  self.announcementType = data.type
  self.jumpId = data.jump_id
  self.hide = data.hide
  self.cacheTimeOut = not self:IsValid(true)
  self.meta = {}
  for i, v in pairs(data.meta) do
    self.meta[v.language] = v
  end
end

function this:IsValid(force)
  if self.hide then
    return false
  end
  if not force and self.cacheTimeOut then
    return false
  end
  if self.id <= 0 then
    return false
  end
  local currTime = L_TimeUtil.getServerTime()
  if currTime >= self.publish_time and currTime <= self.end_time then
  else
    return false
  end
  return true
end

function this:getAnnouncementTab()
  return self.announvementTab
end

function this:getAnnouncementType()
  return self.announcementType
end

function this:getId()
  return self.id
end

function this:getOrderId()
  return self.order_id
end

function this:getPublishTime()
  return self.publish_time
end

function this:getContent()
  local data = self:getDataByLanguage()
  if data == nil then
    return ""
  end
  return data.content
end

function this:getJumpId()
  return self.jumpId
end

function this:getDataByLanguage()
  if self.meta == nil then
    return nil
  end
  local language = C_Define.language
  local curLanguage = "chs"
  if language ~= C_I18NConst.LanguageChs then
    curLanguage = language
  end
  if self.meta[curLanguage] ~= nil then
    return self.meta[curLanguage]
  end
  return nil
end

function this:getTitle()
  local data = self:getDataByLanguage()
  if data == nil then
    return ""
  end
  return data.title
end

function this:getEndTime()
  return self.end_time
end

function this:getStartInterval()
  local currTime = L_TimeUtil.getServerTime()
  local startInterval = self.publish_time - currTime
  if startInterval < 0 then
    startInterval = -1
  end
  return startInterval
end

function this:getReleaseTime()
  local currTime = L_TimeUtil.getServerTime()
  local releaseTime = self.end_time - currTime
  if releaseTime < 0 then
    releaseTime = -1
  end
  return releaseTime
end

return this
