/**
 * Authentication Types - Shared between frontend and backend
 */

/** Token types supported by the system */
export type TokenType = 'pb' | 'graph';

/** Stored token data in cache */
export interface CachedToken {
  token: string;
  refresh_token?: string;
  expiresAt: number;
  userId: string;
  source?: 'cache' | 'refreshed';
}

/** Token response from refresh endpoint */
export interface TokenRefreshResponse {
  token: string;
  expiresAt: number;
  source: 'cache' | 'refreshed';
  type: TokenType;
}

/** User session data from PocketBase */
export interface PocketBaseUser {
  id: string;
  email: string;
  name: string;
  avatar?: string;
  verified: boolean;
  created: string;
  updated: string;
}

/** Alias for PocketBaseUser */
export type User = PocketBaseUser;

/** Authentication state for frontend */
export interface AuthState {
  isAuthenticated: boolean;
  user?: PocketBaseUser | null;
  pbToken?: string | null;
  graphToken?: string | null;
  expiresAt?: number;
}

/** Login callback request body */
export interface LoginCallbackRequest {
  pbToken: string;
  graphToken: string;
  refreshTokenPb?: string;
  refreshTokenGraph?: string;
  user: PocketBaseUser;
}

/** Login callback response */
export interface LoginCallbackResponse {
  success: boolean;
  user: PocketBaseUser;
  expiresAt_pb: number;
  expiresAt_graph: number;
}

/** Logout response */
export interface LogoutResponse {
  success: boolean;
}

/** Token validation result */
export interface TokenValidation {
  valid: boolean;
  expired: boolean;
  expiresIn: number;
  userId?: string;
}
