#pragma once
#include "button_gesture.h"

// Copied under a short critical section. The sampler never touches UI state,
// display locks, I2C, or business reducers.
struct ButtonInputPolicy {
    uint64_t epoch = 0;
    bool allow_long = false;
    bool allow_double = false;
};
struct ButtonSample {
    uint64_t epoch = 0;
    uint64_t sampled_ms = 0;
    uint32_t generation = 0;
    Gesture gesture = Gesture::NONE;
    bool a = false;
    bool edge = false;
    bool down = false;
    bool ready() const { return edge || gesture != Gesture::NONE; }
};
inline ButtonSample sample_button(ButtonGesture &button, bool a, bool raw_down,
                                  uint64_t now, const ButtonInputPolicy &policy) {
    const bool before = button.down();
    const auto gesture = button.update(raw_down, now, policy.epoch,
                                       policy.allow_long, policy.allow_double);
    return {button.epoch, now, 0, gesture, a, before != button.down(), button.down()};
}
