import * as ActionTypes from '../actionTypes'
import { RestoreState, UserLogout } from '../actions'

export enum NostrLoginAuthMethod {
  Connect = 'connect',
  ReadOnly = 'readOnly',
  Extension = 'extension',
  Local = 'local',
  OTP = 'otp'
}

export enum LoginMethod {
  nostrLogin = 'nostrLogin',
  privateKey = 'privateKey',
  register = 'register'
}

export interface Keys {
  private: string
  public: string
}

export interface AuthState {
  loggedIn: boolean
  usersPubkey?: string
  /**
   * sigit login {@link LoginMethod methods }
   * @see {@link LoginMethod}
   */
  loginMethod?: LoginMethod
  /**
   * nostr-login package specific {@link NostrLoginAuthMethod method }
   * @see {@link NostrLoginAuthMethod}
   */
  nostrLoginAuthMethod?: NostrLoginAuthMethod
  /**
   * {@link Keys keyPair} for user auth (usually only public is available)
   * @see {@link Keys}
   */
  keyPair?: Keys
}

export interface SetAuthState {
  type: typeof ActionTypes.SET_AUTH_STATE
  payload: AuthState
}

export interface UpdateLoginMethod {
  type: typeof ActionTypes.UPDATE_LOGIN_METHOD
  payload: LoginMethod | undefined
}

export interface UpdateNostrLoginAuthMethod {
  type: typeof ActionTypes.UPDATE_NOSTR_LOGIN_AUTH_METHOD
  payload: NostrLoginAuthMethod | undefined
}

export interface UpdateKeyPair {
  type: typeof ActionTypes.UPDATE_KEYPAIR
  payload: Keys | undefined
}

export type AuthDispatchTypes =
  | RestoreState
  | SetAuthState
  | UpdateLoginMethod
  | UpdateNostrLoginAuthMethod
  | UpdateKeyPair
  | UserLogout
