package main

import (
	"log"

	"git.joco.dk/snr/fermentord/internal/configuration"
	"git.joco.dk/snr/fermentord/internal/controllers"
	"git.joco.dk/snr/fermentord/internal/hw"
	"git.joco.dk/snr/fermentord/internal/metrics"
)

func gpioSetState(state controllers.ChamberState, gpio *hw.Gpio, config configuration.Configuration) {
	switch state {
	case controllers.ChamberStateIdle:
		log.Printf("Setting chamber state idle")
		metrics.State.Set(metrics.MetricStateIdle)
		gpio.StopCooler()
		gpio.StopHeater()

	case controllers.ChamberStateCooling:
		log.Printf("Setting chamber state cooling")
		metrics.State.Set(metrics.MetricStateCooling)
		gpio.StopHeater()
		if config.CoolerEnabled {
			gpio.StartCooler()
		}

	case controllers.ChamberStateHeating:
		log.Printf("Setting chamber state heating")
		metrics.State.Set(metrics.MetricStateHeating)
		gpio.StopCooler()
		if config.HeaterEnabled {
			gpio.StartHeater()
		}
	}
}
