import type { WebChartTemporalBinningUnits } from "../../../spec/chart-object-literals.js";
import type { TimeIntervalInfo, WebChartDataItem } from "../../../spec/data-source.js";

/** @internal */
export interface DateRange {
  dateMinTimestamp?: number | null;
  dateMaxTimestamp?: number | null;
}

/** @internal */
export interface IntervalUnitHelper {
  unit: WebChartTemporalBinningUnits;
  threshold: number;
  unitMs: number;
  preferredIntervalSize: number[];
}

/** @internal */
export const timeUnitHelper: IntervalUnitHelper[];

/** @internal */
export interface TimeBinningStatistics {
  dateRange: DateRange;
  numberOfFeatures: number;
}

/** @internal */
export interface GroupProps {
  binFirstOrLastIndex: number;
  data: WebChartDataItem[];
  x: string;
  timeIntervalInfo: TimeIntervalInfo;
  newDateMin: number;
  newDateMax: number;
}

/** @internal */
export const groupByWhenCaseForMedianTimeBinning: `{ groupByFieldsForStatistics } WHEN { dateField }>='{ startDate }' AND { dateField }{ endDateOperand }'{ endDate }' THEN '{ y }|{ binIndex}'`;