#pragma once

#include "fgc/Config.h"

#include <memory>
#include <optional>
#include <string>

namespace fgc {

// Command-line / runtime options that override config at launch.
struct RuntimeOptions {
    bool init  = false;  // run the endstop-finding init sequence
    bool start = false;  // begin capture automatically
    bool demo  = false;  // demo mode (copy placeholder image instead of encoding)

    // Tri-state feature overrides (unset => use the config value).
    std::optional<bool> use_mqtt;
    std::optional<bool> mock_camera;
    std::optional<bool> mock_serial;
    std::optional<bool> use_tui;  // --tui / --no-tui; unset => [UI] enable_tui

    std::string log_level;         // empty => default
    std::string trace_categories;  // comma list (serial,mqtt,camera,control,all); empty => unset
    std::string config_path;       // resolved config.ini path (to save calibration back); empty => none
};

// Owns the component lifecycle and the control loop. Builds the concrete
// motor controller, control channel and camera source from config + options
// (real or mock), wires them to the ImagePipeline and CaptureScheduler, and
// runs until "exit" / SIGINT.
class Application {
public:
    Application(AppConfig config, RuntimeOptions options);
    ~Application();

    int run();

private:
    struct Impl;
    std::unique_ptr<Impl> impl_;
};

}  // namespace fgc
