export enum FormInputType {
  CHECKBOX = 'CHECKBOX',
  MULTIPLE_CHOICE = 'MULTIPLE_CHOICE',
  RATING = 'RATING',
  TEXT = 'TEXT',
  DESCRIPTION = 'DESCRIPTION',
}

export interface FormOption {
  id: number;
  label: string;
}

export interface FormStepInput<T extends FormInputType> {
  type: T;
}

export interface FormTextInput extends FormStepInput<FormInputType.TEXT> {
  placeholder?: string;
}

export interface FormCheckboxInput
  extends FormStepInput<FormInputType.CHECKBOX> {
  options: FormOption[];
}

export interface FormMultipleChoiceInput
  extends FormStepInput<FormInputType.MULTIPLE_CHOICE> {
  options: FormOption[];
}

export interface FormRatingInput extends FormStepInput<FormInputType.RATING> {
  options: FormOption[];
}

export interface FormDescriptionInput
  extends FormStepInput<FormInputType.DESCRIPTION> {
  description: string;
  isHtml: boolean;
}

export type FormInput =
  | FormTextInput
  | FormCheckboxInput
  | FormMultipleChoiceInput
  | FormRatingInput
  | FormDescriptionInput;

export interface FormStepRule {
  required?: boolean;
  min?: number;
  max?: number;
}

export type FormValue = string | number | number[];

export type FormValues = {
  [key: string]: {
    value?: FormValue;
    comment?: string;
  };
};

export enum FormCommentableType {
  REQUIRED = 'REQUIRED',
  OPTIONAL = 'OPTIONAL',
  NONE = 'NONE',
}

export type FormStep<M = unknown> = {
  reviewId: number;
  label?: string;
  description?: {
    value: string;
    isHTML?: boolean;
  };
  input: FormInput;
  rules?: FormStepRule;
  name: string;
  answer?: FormValue;
  commentable?: FormCommentableType;
  comment?: string;
  metadata?: M;
};

export interface StepData {
  key: string;
  data: FormStep | FormStep[];
}

export interface SubmitData {
  /**
   * Values filled in the form
   */
  formValues: FormValues;
  /**
   * Time in seconds which the user takes to complete the form
   */
  fillingTime: number;
}

export type CompetencyMetadata = {
  type: 'competency';
  category: {name: string; description: string};
};

export type UserReviewed = {
  firstName: string;
  lastName: string;
  profilePicture?: Nullable<string>;
};
