#pragma once

#include "sensor.h"
#include "switch.h"

#include <can-jf0815-hw.h>
#include <why-spinlock.h>
#include <why-messagequeue.h>


class FSM
{
public:
    enum class State {
        INIT,
        RUNNING,
        OVERTEMP,
        SENSORBURNING,
    };

public:
    FSM(int sensor_burning_irq, Switch& hard_alarm,
        long soft_critical_temp, Switch& soft_alarm,
        int operator_button_irq,
        Why::MessageQueue<State>& state_change_queue,
        Sensor& sensor, Switch& cooling,
        long low_temp, long high_temp);

    void start();

    void timer_tick();                                 // <-- external event

private:
    void _sensor_burning();
    void _operator_button_pressed();

    void _state_change(State state);

private:
    Why::Spinlock _lock;

    int _sensor_burning_irq;
    Switch& _hard_alarm;
    long _soft_critical_temp;
    Switch& _soft_alarm;
    int _operator_button_irq;
    Sensor& _sensor;
    Switch& _cooling;
    long _low_temp;
    long _high_temp;

    Why::MessageQueue<State>& _state_change_queue;

    State _state;
};
