/**
 * Google OAuth2 相关的TypeScript类型定义
 * 基于 docs/google.md API文档
 */

// 基础响应接口
export interface BaseResponse<T = any> {
  success: boolean;
  data?: T;
  error?: string;
  message?: string;
}

// Google 授权URL响应
export interface GoogleAuthorizeResponse {
  authUrl: string;
  state: string;
  clientId: string;
}

// 用户信息接口
export interface GoogleUserInfo {
  userId: string;
  userName: string;
  name: string;
  email: string;
  authType: 'GOOGLE' | 'LOCAL';
  url?: string;
  isNewUser: boolean;
}

// Google 登录成功响应
export interface GoogleLoginSuccessResponse {
  token: string;
  userInfo: GoogleUserInfo;
}

// 邮箱冲突响应数据
export interface EmailConflictData {
  bindToken: string;
  existingUser: {
    email: string;
    authType: 'LOCAL' | 'GOOGLE';
  };
}

// Google 登录请求参数
export interface GoogleLoginRequest {
  idToken: string;
  action?: 'login' | 'register' | 'auto';
  inviteCode?: string; // 邀请码支持
}

// Google 账户绑定请求参数
export interface GoogleBindRequest {
  idToken?: string;
  confirm: boolean;
}

// Google 绑定状态响应
export interface GoogleBindStatusResponse {
  isBound: boolean;
  userId: string;
}

// OAuth 错误类型
export type GoogleOAuthError = 
  | 'INVALID_GOOGLE_TOKEN'
  | 'EMAIL_ALREADY_EXISTS'
  | 'USER_NOT_FOUND'
  | 'REGISTRATION_FAILED'
  | 'GOOGLE_LOGIN_FAILED'
  | 'AUTHORIZATION_URL_GENERATION_FAILED'
  | 'BINDING_FAILED';

// OAuth 回调参数
export interface OAuthCallbackParams {
  code?: string;
  state?: string;
  error?: string;
  error_description?: string;
}

// OAuth 状态管理
export interface OAuthState {
  state: string;
  timestamp: number;
  redirectUrl?: string;
  inviteCode?: string;
}
