/**
 * Auth 状态机：事件联合
 *
 * 事件名与原 Dart AuthEvent 对齐。
 */
import type { AuthProvider } from "@/lib/auth/auth_platform";
import type { AuthPanelMode } from "@/data/dto/auth";

export interface BindFacebookIdentityInput {
  asid?: string;
  psid?: string;
}

export type AuthEvent =
  // 内部 UI 事件
  | { type: "AuthPanelModeChanged"; mode: AuthPanelMode }
  | { type: "AuthLogoutSubmitted" }
  /** App 启动时一次性派发 —— 读 storage 把 loginStatus 同步到状态机 */
  | { type: "AuthInit" }
  | ({ type: "AuthExternalFacebookIdentityBindRequested" } &
      BindFacebookIdentityInput)
  // 业务事件（提交）
  | { type: "AuthGuestLoginSubmitted" }
  | { type: "AuthEmailLoginSubmitted"; email: string; password: string }
  | {
      type: "AuthEmailRegisterSubmitted";
      email: string;
      password: string;
      username: string;
      confirmPassword: string;
    }
  // 社交登录 —— 状态机内部调 next-auth/react 的 signIn(provider)
  | { type: "AuthGoogleLoginSubmitted"; provider: AuthProvider }
  | { type: "AuthFacebookLoginSubmitted"; provider: AuthProvider }
  // OAuth 回调后：把 OAuth provider token 转交后端换业务 token
  // 由 <OAuthSessionSync /> 监听 useSession() 派发
  | { type: "AuthGoogleSyncSubmitted"; idToken: string }
  | { type: "AuthFacebookSyncSubmitted"; accessToken: string };
