import { User } from "../user.js";
import { AuthError, Result } from "./utils.js";

//#region src/auth/methods/signup.d.ts

/**
 * Starts a sign-up flow by emailing a verification code.
 *
 * User only exists once `confirmSignUp` returns the code.
 */
declare function signUp(details: {
  email: string;
  name?: string;
}): Promise<Result<null, AuthError>>;
/**
 * Finishes a sign-up with the emailed code, creating the account and signing
 * the visitor in.
 *
 * `password` is what the account is created with. Leave it out only for an app
 * that signs people in with an emailed code. An app expecting a password
 * rejects a sign-up without one, and the other way round.
 *
 * A `signedIn` result means the visitor is signed in. An app that also asks for
 * an authenticator app answers `authenticatorRequired` instead, naming the step
 * to send them to next.
 */
declare function confirmSignUp(details: {
  email: string;
  code: string;
  name?: string;
  password?: string;
}): Promise<Result<{
  status: "signedIn";
  user: User;
} | {
  status: "authenticatorRequired";
  /**
   * `verify`: they have an authenticator app and owe a code.
   * `setup`: the app requires one and they have none yet.
   * `setupOptional`: same, except they may skip it instead.
   */
  step: "verify" | "setup" | "setupOptional";
}, AuthError>>;
//#endregion
export { confirmSignUp, signUp };