import type { MeasureWidthImpl } from './measure/types';
import type { ScoreTerm } from './scoring/types';

export type OverflowMode = 'ELLIPSIS' | 'CLIP' | 'SYSTEM_DEFAULT';
export type LineMode = 'AUTO' | 'FIXED';
export type TextWrapContext = 'APP' | 'WIDGET';
export type Lang = 'TC' | 'EN';

export type WrapTextConstraints = {
  protectedPhrases?: string[];
  forbiddenBreakRanges?: Array<{ start: number; end: number }>;
};

export type FontSpecInput = {
  fontSize: number;
  fontFamily: string;
  fontWeight: string;
};

export type WrapTextInput = {
  text: string;
  lang: Lang;
  availableWidth: number;
  maxLines: number;
  context: TextWrapContext;
  fontSpec?: Partial<FontSpecInput> | null;
  /** 可选注入测量实现（APP 场景强烈建议提供；WIDGET 默认不启用） */
  measureWidthImpl?: MeasureWidthImpl;
  /**
   * 测量缓存隔离 key（可选）。
   * 口径建议：`APP|ios|<scale?>` / `WIDGET|small`。
   */
  contextProfile?: string;
  overflowMode?: OverflowMode;
  lineMode?: LineMode;
  constraints?: WrapTextConstraints;
  configVersion?: string;
  debug?: boolean;
};

export type WrapTextMeta = {
  configVersion?: string;
  fallback_type?: 'NONE' | 'RELAX_RULES' | 'SYSTEM_DEFAULT';
  overflow_type?: 'NONE' | 'ELLIPSIS' | 'CLIP';
  reason?: 'NO_CANDIDATE' | 'WIDTH_UNKNOWN' | 'WIDOW' | 'PARTICLE' | 'TOO_LONG' | string;
  breaks?: number[];
  scoreTopTerms?: ScoreTerm[];
};

export type WrapTextOutput = {
  lines: string[];
  wrappedText: string;
  meta?: WrapTextMeta;
};

