local this = {}
local _homeSeedTpl = L_GameTpl:getHomeSeedsTpl()
local _homeFieldTpl = L_GameTpl:getHomeFieldtypeTpl()
local _productsTpl = L_GameTpl:getProductsTpl()

function this:getCropGrowParam(seedId, conditions, params)
  local buffData = self:getBuff(L_HomeConst.buffId.CROP_REDUCE_TIME_PERCENT, conditions, params)
  local tpl = _homeSeedTpl:getTplById(seedId)
  local growTime = _homeSeedTpl:getGrowTime(tpl)
  local preHarTime = _homeSeedTpl:getHarvestTime(tpl)
  local growTime = math.floor(growTime * (1 - buffData.buffValue))
  local preHarTime = math.floor(preHarTime * (1 - buffData.buffValue))
  return growTime, preHarTime
end

function this:getProductProduceTime(productId, conditions, params)
  local productTpl = _productsTpl:getTplById(productId)
  if not productTpl then
    errorf("\230\151\160\230\149\136\231\154\132 product ID: " .. productId, 2)
    return 0
  end
  local staticTimeBuffData = self:getBuff(L_HomeConst.buffId.PRODUCT_STATIC_TIME_VALUE, conditions, params)
  if staticTimeBuffData.buffValue ~= 0 then
    return staticTimeBuffData.buffValue
  end
  local buffData = self:getBuff(L_HomeConst.buffId.PRODUCT_REDUCE_TIME_PERCENT, conditions, params)
  local onceTime = _productsTpl:getTime(productTpl)
  local buffValue = buffData.buffValue
  local wildWorldBuffData = self:getWildBuffBuildDataByBuffId(L_HomeConst.buffId.PRODUCT_REDUCE_TIME_PERCENT, conditions)
  if wildWorldBuffData then
    buffValue = buffValue + wildWorldBuffData.buffValue
  end
  local finalTime = onceTime * (1 - buffValue)
  if finalTime <= tonumber(L_Config:getConfig("game", "HOME_PROCESS_PRODUCT_TIME")) then
    finalTime = tonumber(L_Config:getConfig("game", "HOME_PROCESS_PRODUCT_TIME"))
  end
  finalTime = math.floor(finalTime)
  return finalTime
end

function this:getPetEggHatchTimeValue(petEggId, conditions, params)
  local buffData = self:getBuff(L_HomeConst.buffId.PETEGG_HATCHTIME_DECREASE_VALUE, conditions, params)
  local buffValue = buffData.buffValue
  local wildWorldBuffData = self:getWildBuffBuildDataByBuffId(L_HomeConst.buffId.PETEGG_HATCHTIME_DECREASE_VALUE, conditions)
  if wildWorldBuffData then
    buffValue = buffValue + wildWorldBuffData.buffValue
  end
  return buffValue
end

function this:getPetEggHatchTimePercent(petEggId, conditions, params)
  local buffData = self:getBuff(L_HomeConst.buffId.PETEGG_HATCHTIME_DECREASE_PERCENT, conditions, params)
  local buffValue = buffData.buffValue
  local wildWorldBuffData = self:getWildBuffBuildDataByBuffId(L_HomeConst.buffId.PETEGG_HATCHTIME_DECREASE_PERCENT, conditions)
  if wildWorldBuffData then
    buffValue = buffValue + wildWorldBuffData.buffValue
  end
  return buffValue
end

return this
