export interface KBAAnswer {
  id: string;
  text: string;
}

export interface KBAQuestion {
  questionId: string;
  text: string;
  answers: KBAAnswer[];
}

export interface KBAQuestionsResponse {
  auth_token: string;
  auth_method: string;
  questions: KBAQuestion[];
}

export interface KBAOTPResponse {
  auth_token: string;
  auth_method: 'otp';
  oneTimePwd: string;
}

export interface KBAVendorAuthRequest {
  jsc: string;
  hdim: string;
}

export interface KBAVendorAuthResponse {
  auth_token: string;
  auth_method: string;
  questions?: KBAQuestion[];
  oneTimePwd?: string;
}

export interface KBAOTPSubmitRequest {
  auth_type: 'otp';
  auth_token: string;
  otp_code: string;
}

export interface KBAUserAnswer {
  questionId: string;
  answerId: string;
}

export interface KBASubmitRequest {
  auth_token: string;
  auth_pin: string;
  answers: KBAUserAnswer[];
}

export interface KBASubmitResponse {
  success: boolean;
  message?: string;
  error?: string;
}

export type KBAProvider = 'array' | 'spin_wheel' | 'id_iq';

export interface KBAAttemptMetadata {
  remainingAttempts: number;
  totalAttempts: number;
  lastAttemptDate?: string;
}

export type KBAStatus =
  | 'initial'
  | 'questions_loaded'
  | 'otp_required'
  | 'submitting'
  | 'success'
  | 'failed'
  | 'exhausted'
  | 'client_already_authorized';

export interface KBAState {
  status: KBAStatus;
  questions: KBAQuestion[];
  userAnswers: Record<string, string>;
  authToken?: string;
  authMethod?: string;
  otpCode?: string;
  attemptData?: KBAAttemptMetadata;
  error?: string;
  isLoading: boolean;
  isSubmitting?: boolean;
}

export const KBA_CONSTANTS = {
  MAX_ATTEMPTS: 3,
  DEFAULT_PROVIDER: 'array' as KBAProvider,
} as const;
