HolodosTemplates = {}
HolodosTemplates.CheckEngine = {}
HolodosTemplates.CheckOperate = {}
HolodosTemplates.ContainerAccess = {}
HolodosTemplates.Create = {}
HolodosTemplates.Init = {}
HolodosTemplates.InstallComplete = {}
HolodosTemplates.InstallTest = {}
HolodosTemplates.UninstallComplete = {}
HolodosTemplates.UninstallTest = {}
HolodosTemplates.Update = {}
HolodosTemplates.Use = {}

HolodosUtils = {}

local HolodosBatteryChange = -0.00002

function HolodosTemplates.ContainerAccess.Holodos(vehicle, part, chr)
	if chr:getVehicle() == vehicle then
		local seat = vehicle:getSeat(chr)
		return seat == 2 or seat == 4 or seat == 5;
	elseif chr:getVehicle() then
		return false
	end
end

function HolodosTemplates.Create.Holodos(vehicle, part)
	local invItem = VehicleUtils.createPartInventoryItem(part);
	if part:getInventoryItem() and part:getItemContainer() then
		part:getItemContainer():setType("fridge")
	end
end

function HolodosTemplates.Init.Holodos(vehicle, part)
	if part:getInventoryItem() and part:getItemContainer() then
		if vehicle:isEngineRunning() and vehicle:getBatteryCharge() > 0.01 then
			part:getItemContainer():setCustomTemperature(0.2)
		else		
			part:getItemContainer():setCustomTemperature(1.0)
		end
	end
end

function HolodosTemplates.Update.Holodos(vehicle, part, elapsedMinutes)
	local currentTemp = part:getItemContainer():getTemprature()
	local minTemp = 0.2
	local maxTemp = 1.0
	if part:getInventoryItem() and part:getItemContainer() then
		if vehicle:isEngineRunning() and vehicle:getBatteryCharge() > 0.01 then
			if currentTemp < minTemp then
				part:getItemContainer():setCustomTemperature(minTemp)
			elseif currentTemp > minTemp then
				part:getItemContainer():setCustomTemperature(currentTemp - (0.04 * elapsedMinutes))
			end
			VehicleUtils.chargeBattery(vehicle, HolodosBatteryChange * elapsedMinutes)
		else
			if currentTemp < maxTemp then
				part:getItemContainer():setCustomTemperature(currentTemp + (0.04 * elapsedMinutes))
			elseif currentTemp >= maxTemp then
				part:getItemContainer():setCustomTemperature(maxTemp)
			end
		end
	end
end