import { ProjectEditorSectionId } from '../models/project-editor.model';

/**
 * Names of the reusable, centralized validators (implemented under
 * `schema/validators/`). A field references validators by name so the schema
 * stays declarative and no validation logic is duplicated per field.
 */
export type ValidatorName =
  | 'required'
  | 'url'
  | 'email'
  | 'hexColor'
  | 'json'
  | 'css'
  | 'localeCompleteness'
  | 'duplicateRoutes'
  | 'widgetConfig';

export type FieldType =
  | 'text'
  | 'url'
  | 'email'
  | 'color'
  | 'select'
  | 'number'
  | 'toggle'
  | 'json'
  | 'css'
  | 'html'
  | 'locale-map'
  | 'list';

export interface FieldValidatorRef {
  readonly name: ValidatorName;
  readonly params?: Record<string, unknown>;
}

/**
 * Declarative description of one editable field in the Project Editor.
 * The schema is the single source of truth that drives validation, inline
 * error mapping, labels and defaults. Section templates stay hand-authored
 * (metadata-augmented approach) and bind against these keys.
 */
export interface FieldSchema {
  /** Dot path into `BootstrapConfig`, e.g. `theme.palette.primary`. Unique across all sections. */
  readonly key: string;
  /** Editor section the field belongs to (drives per-section grouping/badges). */
  readonly section: ProjectEditorSectionId;
  readonly type: FieldType;
  /** i18n key for the field label. */
  readonly labelKey: string;
  /** i18n key for the field hint/description. */
  readonly hintKey?: string;
  readonly default?: unknown;
  readonly required?: boolean;
  readonly validators?: readonly FieldValidatorRef[];
}
