#pragma once
#include <memory>
#include <mw/database.hpp>
#include "data_source_interface.h"
/// SQLite-backed history; requires SQLite's serialized threading mode.
class DataSourceSqlite final : public DataSourceInterface
{
public:
/// Open or create a database and schema; use :memory: for transient data.
static mw::E<std::unique_ptr<DataSourceSqlite>> open(
const std::string& path);
/// Close the connection and release its resources.
~DataSourceSqlite() override;
/// Append a validated probe result using bound parameters.
mw::E<void> save(const StatusRecord& record) override;
/// Return the latest result, or an empty optional for an unknown service.
mw::E<std::optional<StatusRecord>> latest(
const std::string& service_id) override;
/// Return history in [start, end), ordered by timestamp and insertion.
mw::E<std::vector<StatusRecord>> history(
const std::string& service_id, std::int64_t start,
std::int64_t end) override;
private:
explicit DataSourceSqlite(std::unique_ptr<mw::SQLite> database);
std::unique_ptr<mw::SQLite> database;
};