export type ControlType = 'text' | 'dropdown' | 'checkbox' | 'date' | 'multiline';

export type FieldMode = 'single' | 'repeat';

export interface DropdownOption {
  display: string;
  value: string;
}

export interface RawTypeConfig {
  controlType: string;
  placeholder?: string;
  defaultValue?: string;
  defaultChecked?: boolean;
  options?: DropdownOption[];
  defaultOptionValue?: string;
}

export type TypeConfigValidationField = 'control-type' | 'text-default' | 'dropdown-options' | 'dropdown-default' | 'date-default';

export type ValidationResult<T, F extends string = string> = { ok: true; value: T } | { field: F; message: string; ok: false };

export interface ValidatedDropdownConfig {
  controlType: 'dropdown';
  options: DropdownOption[];
  placeholder: string;
  selectedIndex: number;
}

export interface ValidatedStandardConfig {
  controlType: Exclude<ControlType, 'dropdown'>;
  defaultChecked: boolean;
  defaultValue: string;
  placeholder: string;
}

export type ValidatedTypeConfig = ValidatedDropdownConfig | ValidatedStandardConfig;

export interface FieldDefinitionInput {
  alias: string;
  fieldCode: string;
  groupCode: string;
  mode: FieldMode;
  rowId: string;
  typeConfig: RawTypeConfig | null | undefined;
}

export type FieldDefinitionValidationField = 'field-code' | 'field-alias' | 'group-code' | 'row-id' | TypeConfigValidationField;

export interface FieldColor {
  B: number;
  G: number;
  R: number;
}

interface FieldDefinitionBase {
  alias: string;
  color: FieldColor;
  fieldCode: string;
  groupCode: string;
  mode: FieldMode;
  rowId: string;
  tag: string;
}

export type FieldDefinition = FieldDefinitionBase & (ValidatedDropdownConfig | ValidatedStandardConfig);
