/**
 * Reset Password ViewModel
 * 
 * Client-side state management for reset password flow.
 * Immutable, class-based, contains only UI state.
 */

export interface ResetPasswordFormField {
  value: string;
  error?: string;
  touched: boolean;
  validating: boolean;
}

export interface ResetPasswordFormState {
  fields: {
    newPassword: ResetPasswordFormField;
    confirmPassword: ResetPasswordFormField;
  };
  isValid: boolean;
  isSubmitting: boolean;
  submitError?: string;
  submitCount: number;
}

export interface ResetPasswordUIState {
  showPassword: boolean;
  showConfirmPassword: boolean;
}

export class ResetPasswordViewModel {
  constructor(
    public readonly token: string,
    public readonly returnTo: string,
    public readonly formState: ResetPasswordFormState,
    public readonly uiState: ResetPasswordUIState,
    public readonly showSuccess: boolean = false,
    public readonly successMessage: string | null = null,
    public readonly mutationPending: boolean = false,
    public readonly mutationError: string | null = null
  ) {}

  withFormState(formState: ResetPasswordFormState): ResetPasswordViewModel {
    return new ResetPasswordViewModel(
      this.token,
      this.returnTo,
      formState,
      this.uiState,
      this.showSuccess,
      this.successMessage,
      this.mutationPending,
      this.mutationError
    );
  }

  withUIState(uiState: ResetPasswordUIState): ResetPasswordViewModel {
    return new ResetPasswordViewModel(
      this.token,
      this.returnTo,
      this.formState,
      uiState,
      this.showSuccess,
      this.successMessage,
      this.mutationPending,
      this.mutationError
    );
  }

  withSuccess(successMessage: string): ResetPasswordViewModel {
    return new ResetPasswordViewModel(
      this.token,
      this.returnTo,
      this.formState,
      this.uiState,
      true,
      successMessage,
      false,
      null
    );
  }

  withMutationState(pending: boolean, error: string | null): ResetPasswordViewModel {
    return new ResetPasswordViewModel(
      this.token,
      this.returnTo,
      this.formState,
      this.uiState,
      this.showSuccess,
      this.successMessage,
      pending,
      error
    );
  }

  get isSubmitting(): boolean {
    return this.formState.isSubmitting || this.mutationPending;
  }

  get submitError(): string | undefined {
    return this.formState.submitError || this.mutationError || undefined;
  }
}