import type { FormFieldConfig, FormSectionConfig } from '@ema-platform/api';

/** One field reachable by a condition's dot path, with enough of its config
 * to drive the value picker (SELECT offers its options; everything else is
 * free text/number/boolean). */
export interface ConditionTarget {
  /** `${sectionKey}.${fieldKey}` — what `FieldCondition.field` expects. */
  path: string;
  field: FormFieldConfig;
}

/**
 * Every field in the schema a condition could point at.
 *
 * Drives the condition builder's autocomplete and its options-aware value
 * picker — typing `certificate.` suggests `certificate.rank` because that
 * section/field exists in this licence type's own schema, not because the
 * rank list is known anywhere in the frontend.
 */
export function collectConditionTargets(sections: FormSectionConfig[]): ConditionTarget[] {
  const targets: ConditionTarget[] = [];
  for (const section of sections) {
    for (const field of section.fields ?? []) {
      targets.push({ path: `${section.key}.${field.key}`, field });
    }
  }
  return targets;
}
