local this = {}
local homeScienceTpl = L_GameTpl.getHomeScienceTpl()
local homeScienceTypeTpl = L_GameTpl.getHomeScienceTypeTpl()

function this:init()
  this.super.init(self)
  self.data = {
    scienceInfoMap = {},
    research_id = 0,
    finish_time = 0,
    scienceLevelRecord = {}
  }
end

function this:getNodeInfo(id)
  return self.data.scienceInfoMap[id] or {
    state = L_Const.homeScienceNodeState.lock
  }
end

function this:getScienceLevel(id)
  return self.data.scienceLevelRecord[id] or 0
end

function this:getResearchingInfo()
  if self.data.research_id and self.data.research_id ~= 0 then
    return {
      research_id = self.data.research_id,
      finish_time = self.data.finish_time
    }
  end
end

function this:getIsRed()
  local info = self:getResearchingInfo()
  if info and info.research_id ~= 0 then
    return 0
  end
  local homeScienceTypeTplArray = homeScienceTypeTpl:getArray()
  for k, v in pairs(homeScienceTypeTplArray) do
    local level = L_HomeScienceStore:getScienceLevel(v.id)
    local typeTpl = homeScienceTypeTpl:getTplById(v.id)
    local maxLevel = homeScienceTypeTpl:getMaxLevel(typeTpl)
    if not (level >= maxLevel) then
      local tpl = homeScienceTpl:getTplByTypeAndLevel(v.id, level + 1)
      local scienceId = homeScienceTpl:getId(tpl)
      local nodeInfo = L_HomeScienceStore:getNodeInfo(scienceId)
      if nodeInfo.state ~= L_Const.homeScienceNodeState.lock and not (L_HomeResidentStore:getRestResidentNum() < homeScienceTpl:getNeedWorkerNum(tpl)) then
        local needItems = homeScienceTpl:getNeedItem(tpl)
        for k, v in ipairs(needItems) do
          if L_BagStore:getItemNum(v[2]) < v[3] then
            goto lbl_78
          end
        end
        return 1
      end
    end
    ::lbl_78::
  end
  return 0
end

return this
