local max = 99
local maxVent = 90
local minVent = 95
local min = 80

local function getValue()
    return turbine.getSteamFilledPercentage() * 100
end

local function color()
    local value = getValue()
    return colors.black
end



local function checkSteamLevel()
    local value = getValue()
    if value > max then
        print("Warning: Steam above maximum! Taking action.")
        reactor.scram();
        turbine.setDumpingMode("DUMPING")
        burnRateDriver.stepDown()
    elseif value >= maxVent-1 then
        print("Steam within vent range. Adjusting vents.")
        turbine.setDumpingMode("DUMPING")
        burnRateDriver.stepDown()
    elseif value >= min and value < minVent then
        print("Steam within normal operation range.")
        turbine.setDumpingMode("IDLE")
        --burnRateDriver.stepDown()
    elseif value < min then
        print("Warning: Steam below minimum! Taking action.")
        turbine.setDumpingMode("IDLE")
    end
end

local function startup()
    return
end

local function shutdown()
end

local function watch()
    while true do
        checkSteamLevel()
        sleep(0.05)  -- Update every tenth second
    end
end

local function report()
        local color = color()
        monitor.setBackgroundColor(color)
        value = getValue()

        setNewLine()
        monitor.write("Turbine Steam: " .. value .. "%")

        setNewLine()
        monitor.write("Turbine Vent: " .. turbine.getDumpingMode())
end

return { report = report, watch = watch, startup = startup, shutdown = shutdown }