local this = {}

function this:checkCondition(entity, param)
  return true
end

function this:getSatisfyCondStroyList(splitList)
  local canPlay = {}
  local timerPeriod = C_GameTime:GetCurPeriod().value__
  local evening = CS.Lens.Gameplay.Modules.Azur.ETimePeriod.Evening.value__
  for k, v in pairs(splitList) do
    if v:sub(#v, #v) == "D" then
      if timerPeriod < evening then
        local str = string.gsub(v, "D", "")
        table.insert(canPlay, str)
      end
    elseif v:sub(#v, #v) == "N" then
      if timerPeriod >= evening then
        local str = string.gsub(v, "N", "")
        table.insert(canPlay, str)
      end
    else
      table.insert(canPlay, v)
    end
  end
  return canPlay
end

function this:executeInteract(entity, param)
  local splitList = string.split(param, ",")
  splitList = this:getSatisfyCondStroyList(splitList)
  local canPlay = {}
  if splitList and 0 < #splitList then
    for k, v in pairs(splitList) do
      if v:sub(1, 1) == "S" then
        local str = string.gsub(v, "S", "")
        local storyId = tonumber(str)
        if AzurWorld.StoryMgr:IsStoryCanPlay(storyId) then
          AzurWorld.StoryMgr:PlayStory(storyId)
          return
        end
      else
        local storyId = tonumber(v)
        if AzurWorld.StoryMgr:IsStoryCanPlay(storyId) then
          table.insert(canPlay, storyId)
        end
      end
    end
  end
  if 0 < #canPlay then
    local idx = math.random(1, #canPlay)
    AzurWorld.StoryMgr:PlayStory(canPlay[idx])
  end
end

function this:getDisplayName(entity, param)
  return nil
end

return this
