local this = {}
local _commonPetSatietyTpl = L_GameTpl:getCommonPetSatietyTpl()

function this:init()
  this.super.init(self)
end

function this:getPetSatiety(petGuid)
  if math.isEmpty(petGuid) then
    return 0
  end
  return L_PetStore:getPetItem(petGuid).satiety
end

function this:getPetMaxSatiety(petGuid)
  if math.isEmpty(petGuid) then
    return math.maxinteger
  end
  local pet = L_PetStore:getPetItem(petGuid)
  local petHomeTalentTpl = L_GameTpl:getPetHomeTalentTpl()
  local talentTpl = petHomeTalentTpl:getTplById(pet.petId)
  if talentTpl then
    local petMaxSatiety = petHomeTalentTpl:getSatietyScore(talentTpl)
    return petMaxSatiety
  end
  return math.maxinteger
end

function this:getPetSatietyPercent(petGuid)
  return self:getPetSatiety(petGuid) / self:getPetMaxSatiety(petGuid)
end

function this:getPetSatietyStatus(petGuid, satietyPer)
  local percent = satietyPer or self:getPetSatietyPercent(petGuid)
  for _, v in pairs(_commonPetSatietyTpl:getValue()) do
    for min, max in pairs(v.satiety) do
      if percent >= min / 10000 and percent <= max / 10000 then
        return v.id
      end
    end
  end
  return L_PetConst.SatietyStatus.FULL
end

function this:isBuildingPause(buildingGuid)
  local buildData = L_HomeStore:getHomeBuildingByGuid(buildingGuid)
  if buildData and not math.isEmpty(buildData.station_pet_guid) then
    return self:isWorkPause(buildData.station_pet_guid) or self:isEating(buildData.station_pet_guid)
  end
  return false
end

function this:isWorkPause(petGuid)
  if self:isEating(petGuid) then
    return true
  end
  local pet = L_PetStore:getPetItem(petGuid)
  if pet then
    return pet.work_pause
  else
    printf("satietyState:isWorkPause", string.format("\232\173\166\229\145\138\239\188\154\230\151\160\230\179\149\230\137\190\229\136\176\229\133\183\230\156\137\231\187\153\229\174\154petGuid %s \231\154\132\229\174\160\231\137\169\230\156\141\229\138\161\229\153\168\230\149\176\230\141\174\227\128\130", petGuid))
    return false
  end
end

function this:isEating(petGuid)
  local pet = L_PetStore:getPetItem(petGuid)
  if pet then
    return not math.isEmpty(pet.canteen_id)
  end
  return false
end

return this
