// compute_stage — Pure TQL stage execution (filter → group+agg|passthrough → sort).
// Part of issue 0081-B: promoted from primitives_gallery playground to registry.
// No ImGui, no I/O. Depends only on data_table_types.h.
#pragma once

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

namespace data_table {

// ----------------------------------------------------------------------------
// aggregation_alias — Pure: default alias when agg.alias is empty.
//   count          -> "count"
//   distinct col   -> "distinct_<col>"
//   percentile p   -> "p<arg*100>_<col>"   (e.g. p95_size_kb)
//   other          -> "<fn>_<col>"          (e.g. avg_size_kb)
// ----------------------------------------------------------------------------
std::string aggregation_alias(const Aggregation& a);

// aggregation_type — Pure: output ColumnType of an aggregation.
ColumnType aggregation_type(const Aggregation& a,
                            const std::vector<std::string>& in_headers,
                            const std::vector<ColumnType>&  in_types);

// apply_filters — Pure: returns indices of rows passing all filters.
// Uses compare() for each cell vs filter value/op.
std::vector<int> apply_filters(const char* const* cells, int rows, int cols,
                               const std::vector<Filter>& filters);

// compute_stage — Pure: executes one Stage over in_cells.
// Pipeline: apply_filters -> (group+agg | passthrough) -> sort.
// Returns a StageOutput owning its cell_backing and cells pointer list.
StageOutput compute_stage(const char* const* in_cells, int in_rows, int in_cols,
                          const std::vector<std::string>& in_headers,
                          const std::vector<ColumnType>&  in_types,
                          const Stage& stage);

} // namespace data_table
