local this = {}

function this:init()
  this.super.init(self)
  self.data = {
    dungeonCampaignInfo = {},
    dungeonInstanceInfo = {},
    dungeonCampaignEnd = {}
  }
  AzurWorld.DungeonMgr:SetServerInfoSyncLuaCallback(handler(self, self.onServerInfoSync))
end

function this:onServerInfoSync()
  self:call(self.event.syncCurDungeon, self:getDungeonCampaignInfoCSData())
end

function this:getDungeon(guid)
  return self.data.dungeonInstanceInfo.infos[guid] or {}
end

function this:getAllDungeonObj()
  return self.data.dungeonInstanceInfo.entrys or {}
end

function this:getIsSuccess(dungeonId)
  local dungeon = self:getDungeon(dungeonId)
  if not table.isEmpty(dungeon) then
    return not math.isEmpty(dungeon.success_time)
  end
  return false
end

function this:getDungeonStar(dungeonId)
  local dungeon = self:getDungeon(dungeonId)
  if not table.isEmpty(dungeon) then
    return L_CommonUtil.numberToBool(dungeon.ins_star)
  end
  return {}
end

function this:getDungeonUpCount(dungeonId)
  local dungeon = self:getDungeon(dungeonId)
  if not L_TimeUtil.isSameDay(dungeon.up_refresh_time or 0, L_TimeUtil.getServerTime()) then
    return 0
  end
  return dungeon.up_num or 0
end

function this:getDungeonCampaignInfoCSData()
  return AzurWorld.DungeonMgr:GetServerDungeonInfo()
end

function this:getReward()
  return AzurWorld.DungeonMgr:GetReward()
end

function this:getStarRunning()
  local res = L_CommonUtil.numberToBool(self:getDungeonCampaignInfoCSData().star)
  return res
end

function this:getStatus()
  return self:getDungeonCampaignInfoCSData().state
end

function this:getUseTime()
  return self.data.dungeonCampaignEnd.use_time
end

function this:getRewardSettle()
  local first = self.data.dungeonCampaignEnd.first_rewards.rewards or {}
  local normal = self.data.dungeonCampaignEnd.drop_rewards.rewards or {}
  local star = self.data.dungeonCampaignEnd.star_rewards.rewards or {}
  local item = self.data.dungeonCampaignEnd.item_rewards.rewards or {}
  local res = {}
  for i, v in pairs(first) do
    table.insert(res, v)
  end
  for i, v in pairs(normal) do
    table.insert(res, v)
  end
  for i, v in pairs(star) do
    table.insert(res, v)
  end
  for i, v in pairs(item) do
    table.insert(res, v)
  end
  return res
end

function this:isInDungeon()
  return self:getStatus() == CS.Protocal.Cs.CampaignStatusType.CstStart
end

return this
