local this = {}

function this:init()
  this.super.init(self)
  self.data = {
    spiritronList = {},
    spiritStoryList = {}
  }
end

function this:state()
  return {}
end

function this:getSpiritronList()
  return self.data.spiritronList
end

function this:getSpiritronListCount()
  local count = 0
  for i, v in pairs(self.data.spiritronList) do
    count = count + 1
  end
  return count
end

function this:getSpiritronItem(uid, isCreate)
  local entity = self.data.spiritronList[uid]
  if entity == nil and isCreate then
    entity = self:createSpiritronData(uid)
    self.data.spiritronList[uid] = entity
  end
  return entity
end

function this:createSpiritronData(uid)
  local entity = require(L_R.store .. "spiritron.spiritronItem").new()
  entity.guid = uid
  return entity
end

function this:getSpiritronConfigId(spiritron)
  return spiritron.spiritronId
end

function this:getHasSpiritron(spiritronConfigId)
  for i, v in pairs(self:getSpiritronList()) do
    if self:getSpiritronConfigId(v) == spiritronConfigId then
      return true
    end
  end
  return false
end

function this:getSpiritronNum(cfgId)
  local count = 0
  for i, v in pairs(self:getSpiritronList()) do
    if self:getSpiritronConfigId(v) == cfgId then
      count = count + 1
    end
  end
  return count
end

function this:isSpiritStoryPlayed(spId)
  return table.containsValue(self.data.spiritStoryList, spId)
end

return this
