-- ************************************ Station ************************************ --
CosmeticTableStation = deriveLuaClass("CosmeticTableStation", "WorkStation")

function CosmeticTableStation:init(desc)
	self.workAnimationFrameTime = 100
	CosmeticTableStation.superInit(desc)

	self.workAnimationFrameTime = self.workAnimationFrameTime or desc.workAnimationFrameTime

	self.stockImage = self:newChild({class="Sprite", x=28, y=1, image="ROOM4_NITROGEN_STOCK:objects"})
	local frame = self.stock - 1
	if (frame < 0) then
		self.stockImage:setVisible(false)
	else
		self.stockImage:setFrame(frame)
	end

end

function CosmeticTableStation:hasWorkToDo()
	return true
end

function CosmeticTableStation:addToStationTask()
	if (CosmeticTableStation.super.addToStationTask(self)) then
		return true
	end
	self:stopFaultySelectionBlink()
	return false
end

function CosmeticTableStation:onDisplayStockChange()
	if (self.stock == 0) then
		self.stockImage.visible = false
	else
		self.stockImage.visible = true
		self.stockImage:setFrame(self.stock-1)
		self:removeOverhead()
	end
end

function CosmeticTableStation:onWorkStart(task)
	local r = CosmeticTableStation.super.onWorkStart(self, task)
	if (self.stock == self.maxStock) then
		return false
	end
	hero:playAnimation(self.workAnimation, -1, "default", self.workAnimationFrameTime)
	task.duration = self.workDuration
	self:playSample("SND_RESTOCK_ROBES:sound") -- Yes, robes...
	return r
end

function CosmeticTableStation:onWorkFinish(task)
	CosmeticTableStation.super.onWorkFinish(self, task)
	self:resetStock()
	self:onDisplayStockChange()
end
