local this = {}

function this:init()
  this.super.init(self)
  self.data = {
    curRogue = require(L_R.store .. "rogue.data.rogueProgress").new(),
    external = {},
    rewardStorage = {}
  }
end

function this:getIsInRogue()
  return not math.isEmpty(self:getStrategy()) and self:getInRogue()
end

function this:getCurRogue()
  return self.data.curRogue
end

function this:getRunningDialog()
  local runningEvent = self:getRunningEvent()
  if not table.isEmpty(runningEvent) then
    local dialogs = self:getDialogs()
    return dialogs[runningEvent:getGuid()]
  end
end

function this:getCurRogueStoryId()
  local runningDialog = self:getRunningDialog()
  if not table.isEmpty(runningDialog) then
    return runningDialog.dialog
  end
end

function this:getRewardStorage()
  return self.data.rewardStorage
end

function this:getRogueStatus()
  return self.data.curRogue.status
end

function this:getInRogue()
  return self.data.curRogue.in_rogue
end

function this:getPos()
  return self.data.curRogue.pos
end

function this:getRot()
  return self.data.curRogue.rot
end

function this:getRoom()
  return self.data.curRogue.room
end

function this:getCurRoomOrder()
  return self:getRoom().room_order
end

function this:getCurRoomMap()
  return self:getRoom().room_map
end

function this:getNextRoomInfo()
  return self:getRoom().next_rooms
end

function this:getNextRoom(passOrder)
  return self:getRoom().next_rooms[passOrder]
end

function this:getLv()
  return self.data.curRogue.lv
end

function this:getExp()
  return self.data.curRogue.exp
end

function this:getEntropy()
  return self.data.curRogue.entropy
end

function this:getAtt()
  return self.data.curRogue.attrs or {}
end

function this:getInfos()
  return self.data.curRogue.infos or {}
end

function this:getRogueInfo(uid)
  return self:getInfos(uid)
end

function this:getEchoes()
  return self.data.curRogue.echos or {}
end

function this:getRogueEcho(uid)
  return self:getEchoes()[uid]
end

function this:getCurrency()
  return self.data.curRogue.currency
end

function this:getStrategy()
  return self.data.curRogue.strategy
end

function this:getCommon()
  return self.data.curRogue.common
end

function this:getChallenge()
  return self.data.curRogue.challenge
end

function this:getHadHeroes()
  return self.data.curRogue.had_heros
end

function this:getHadPets()
  return self.data.curRogue.had_pets
end

function this:getHeroes()
  return self.data.curRogue.heros or {}
end

function this:getOrnaments()
  return self.data.curRogue.ornaments
end

function this:getPets()
  return self.data.curRogue.pets
end

function this:getSpiritrons()
  return self.data.curRogue.spiritrons
end

function this:getRewards()
  return self.data.curRogue.rewards
end

function this:getRogueReward(uid, isCreate)
  local entity = self:getRewards()[uid]
  if entity == nil and isCreate then
    entity = require(L_R.store .. "rogue.data.rogueReward").new()
    entity.guid = uid
  end
  self.data.curRogue.rewards[uid] = entity
  return entity
end

function this:getHasRewards()
  local rewards = self:getRewards()
  return table.count(rewards) ~= 0
end

function this:getSrc()
  return self.data.curRogue.src
end

function this:getRoomEvents()
  return self.data.curRogue.room_events
end

function this:getBoosId()
  return self.data.curRogue.boss_id
end

function this:getDelEchos()
  return self.data.curRogue.del_echos
end

function this:getNowEffect()
  return self.data.curRogue.now_effect
end

function this:getTriggers()
  return self.data.curRogue.triggers
end

function this:getTypeTriggers(type)
  return self:getTriggers()[type]
end

function this:getTrigger(type, guid)
  return self:getTypeTriggers(type).triggers[guid]
end

function this:getTriggerByEchoId(echoId)
  for i, type in pairs(self:getTriggers()) do
    local triggers = type.triggers
    for _, trigger in pairs(triggers) do
      if trigger.echo == echoId then
        return trigger
      end
    end
  end
end

function this:getTriggerEffects()
  return self.data.curRogue.trigger_effects
end

function this:getTriggerEffect(uid)
  return self:getTriggerEffects()[uid]
end

function this:getOperas()
  return self.data.curRogue.operas
end

function this:getRogueUsingTime()
  return self.data.curRogue.use_time
end

function this:getDifficulty()
  return self.data.curRogue.difficulty
end

function this:getShops()
  return self.data.curRogue.shops
end

function this:getShopsItem(eventId)
  return self.data.curRogue.shops[eventId]
end

function this:getDialogs()
  return self.data.curRogue.dialogs
end

function this:getRogueHero(heroGuid)
  return self:getHeroes()[heroGuid]
end

function this:getRogueAccessory(guid, isCreate)
  local accessoryList = self:getOrnaments()
  local entity = accessoryList[guid]
  if entity == nil and isCreate then
    entity = require(L_R.store .. "accessory.data.accessory").new()
    accessoryList[guid] = entity
    entity.guid = guid
  end
  return entity
end

function this:getRogueSpiritron(uid, isCreate)
  local spiritrons = self:getSpiritrons()
  local entity = spiritrons[uid]
  if entity == nil and isCreate then
    entity = require(L_R.store .. "spiritron.spiritronItem").new()
    spiritrons[uid] = entity
    entity.guid = uid
  end
  return entity
end

function this:getRoguePet(uid, isCreate)
  local pets = self:getPets()
  local entity = pets[uid]
  if entity == nil and isCreate then
    entity = require(L_R.store .. "pet.data.petItem").new()
    pets[uid] = entity
    entity.guid = uid
  end
  return entity
end

function this:getRogueEvent(uid, isCreate)
  local events = self:getRoomEvents()
  local entity = events[uid]
  if entity == nil and isCreate then
    entity = require(L_R.store .. "rogue.data.rogueEvent").new()
    events[uid] = entity
    entity.guid = uid
  end
  return entity
end

function this:getRunningEvent()
  local events = self:getRoomEvents()
  for i, event in pairs(events) do
    if event:getStatus() == L_RogueConst.roomEventStatus.running then
      return event
    end
  end
end

function this:getDialogDiceRes()
  local dialog = self:getRunningDialog()
  local res = dialog and dialog.res or 0
  local hasResult = res ~= L_RogueConst.dialogDiceRes.running
  local isWin = hasResult and res == L_RogueConst.dialogDiceRes.win
  return hasResult, isWin
end

return this
