import type { UseFormReturn } from 'react-hook-form';
import type { z } from 'zod';
import type { OtpVerificationMode, otpFormSchema } from '../../validations';
export type { OtpVerificationMode };
/** Form values for the OTP verification form, inferred from the Zod schema. */
export type OtpFormValues = z.infer<typeof otpFormSchema>;
/**
 * Consumer-provided custom validator for OTP. Runs after the built-in
 * 6-digit check passes. Return `true` to accept, or a string message to
 * surface as the field error (and block submission). May be async so
 * callers can hit a backend pre-check before the full verify call.
 */
export type OtpValidateFn = (otp: string) => string | true | Promise<string | true>;
/** Options for the `useOtpVerification` hook controlling mode, submission, and callbacks. */
export interface UseOtpVerificationOptions {
    /** OTP mode: phone (60s cooldown) or email (2 min cooldown). */
    mode: OtpVerificationMode;
    /** Sync callback with OTP string. Use when parent owns API (e.g. AuthFlow). Ignored when submitApi is provided. */
    onSubmit?: ((otp: string) => void) | undefined;
    /** Called when the user requests a new OTP code (resend). Ignored when submitApi is provided. */
    onResendCode?: (() => void) | undefined;
    /** When provided, hook runs: validate → submitApi(otp) → onSuccess(). Consumer passes redirect in onSuccess. */
    submitApi?: ((otp: string) => Promise<void>) | undefined;
    /** Called after submitApi resolves (e.g. router.push('/dashboard')). */
    onSuccess?: (() => void) | undefined;
    /** Called when submitApi rejects or throws. */
    onError?: ((error: unknown) => void) | undefined;
    /**
     * Optional custom OTP validator. Runs after the built-in digit check.
     * Return `true` to accept, or a string to surface as the field error
     * and block submission.
     */
    validate?: OtpValidateFn | undefined;
}
/** Return value of the `useOtpVerification` hook, providing form state and resend controls. */
export interface UseOtpVerificationReturn {
    /** react-hook-form methods bound to the OTP form. */
    methods: UseFormReturn<OtpFormValues>;
    /** Submit handler to pass to the form's `onSubmit`. Validates and dispatches the OTP. */
    handleSubmit: (data: OtpFormValues) => void;
    /** True when current form values pass validation (for disabling Submit until valid – edge case 6). */
    isFormValid: (data: OtpFormValues) => boolean;
    /** Triggers a resend of the OTP code and resets the cooldown timer. */
    handleResend: () => void;
    /** Seconds remaining before the user can request another OTP code. */
    resendSecondsLeft: number;
    /** True when the resend cooldown has elapsed and the user may request a new code. */
    canResend: boolean;
    /** Human-readable countdown string (e.g. `"00:45"`) for display next to the resend button. */
    timerText: string;
    /** True while submitApi is in flight. */
    isSubmitting: boolean;
}
