// tql_helpers — Pure token helpers for TQL (Table Query Language).
// Promoted from primitives_gallery playground to registry, issue 0081-C.
// No ImGui, no I/O, no Lua. Pure string<->enum conversions used by tql_emit
// and tql_apply.
#pragma once

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

namespace data_table {

// Op <-> token (TQL wire format).
const char* op_label(Op o);
Op          op_from_label(const char* s);

// ColumnType <-> string.
const char* column_type_name(ColumnType t);
ColumnType  column_type_from_string(const std::string& s);

// AggFn <-> token.
const char* agg_fn_token(AggFn f);
AggFn       agg_fn_from_string(const std::string& s);

// ViewMode <-> token (Lua string used in TQL "display" field).
const char* view_mode_token(ViewMode m);
ViewMode    view_mode_from_token(const char* s);

// JoinStrategy <-> token.
const char* join_strategy_token(JoinStrategy s);
JoinStrategy join_strategy_from_token(const char* s);

// aggregation_alias — pure: default alias when agg.alias is empty.
std::string aggregation_alias(const Aggregation& a);

// parse_breakout_granularity — splits "col:granularity" into col + gran.
// Returns DateGranularity::None if no suffix or unrecognised suffix.
DateGranularity parse_breakout_granularity(const std::string& breakout,
                                           std::string& col_out);

// Lua string literal escaping used in TQL emit.
std::string lua_string_literal(const std::string& s);

// Color <-> hex string ("#rrggbb" / "#rrggbbaa").
std::string  color_to_hex(unsigned int c);
unsigned int hex_to_color(const std::string& s);

// DateGranularity <-> token.
const char*      date_granularity_token(DateGranularity g);
DateGranularity  date_granularity_from_token(const char* s);

} // namespace data_table
