// tql_emit — Pure serialization of data_table::State to TQL Lua text.
// TQL (Table Query Language): canonical Lua chunk format for State round-trips.
// Promoted from primitives_gallery playground to registry, issue 0081-C.
//
// No ImGui, no I/O, no Lua runtime. Pure string generation.
// Depends only on data_table_types.h + tql_helpers.h.
#pragma once

#include "core/data_table_types.h"
#include <string>
#include <vector>

namespace tql {

// emit — Serialize a State to a complete Lua chunk (TQL v1).
//
// Parameters:
//   state   — the current view/pipeline state to serialize.
//   headers — original column names (size = orig_cols). Derived cols are
//             taken automatically from state.stages[0].derived.
//   types   — column types for the original columns. Missing entries default
//             to ColumnType::Auto.
//
// Returns a UTF-8 Lua chunk that starts with a comment header and ends with
// "return { version=1, display=..., stages=..., columns=..., views=... }".
// The output is self-contained and parseable with tql_apply without any extra
// context (modulo formula evaluation, which requires a Lua engine).
std::string emit(const data_table::State& state,
                 const std::vector<std::string>& headers,
                 const std::vector<data_table::ColumnType>& types);

} // namespace tql
