local this = class("characterActionTpl")

function this:init(config)
  self.config = config
  self.data = {}
  for i, v in pairs(config) do
    if self.data[v.GroupId] == nil then
      self.data[v.GroupId] = {}
    end
    table.insert(self.data[v.GroupId], v)
  end
  for _, v in pairs(self.data) do
    table.sort(v, function(a, b)
      return a.id < b.id
    end)
  end
end

function this:getTplByActionId(actionId)
  return self.config[actionId]
end

function this:getGroup(groupId)
  return self.data[groupId]
end

function this:getTpl(groupId, step)
  local group = self.data[groupId]
  return group[step]
end

function this:getGroupId(tpl)
  return tpl.GroupId
end

function this:getStepIndex(tpl)
  return tpl.id % tpl.GroupId
end

function this:getName(tpl)
  return tpl.name
end

function this:getActionId(tpl)
  return tpl.actionId
end

function this:getAction(tpl)
  if tpl.action ~= "" then
    return tpl.action
  end
end

function this:getTime(tpl)
  return tpl.time
end

function this:getLoop(tpl)
  return tpl.loop == 1
end

function this:getInitPosition(tpl)
  local str = tpl.initPosition
  if not string.isEmpty(str) then
    return string.toVector3(str)
  end
end

function this:getInitRotation(tpl)
  local str = tpl.initRotation
  if not string.isEmpty(str) then
    return string.toVector3(str)
  end
end

function this:getFinPos(tpl)
  local str = tpl.finPosition
  if not string.isEmpty(str) then
    return string.toVector3(str)
  end
end

function this:getFinRotation(tpl)
  local str = tpl.finRotation
  if not string.isEmpty(str) then
    return string.toVector3(str)
  end
end

function this:getMountAction(tpl)
  if tpl.mountAction ~= 0 then
    return tpl.mountAction
  end
end

function this:getEffectTime(tpl)
  if tpl.effectTime ~= 0 then
    return tpl.effectTime
  end
end

function this:getBreakTime(tpl)
  if tpl.breakTime ~= 0 then
    return tpl.breakTime
  end
end

function this:getWeaponDisTime(tpl)
  if tpl.weaponDisTime ~= 0 then
    return tpl.weaponDisTime
  end
end

return this
