/**
 * Zod schema for OAuthTokenResponse
 *
 * This schema provides runtime validation and type inference.
 *  * Response with JWT tokens after OAuth authentication.

When 2FA is required:
- requires_2fa: True
- session_id: UUID of 2FA verification session
- access/refresh/user: null

When 2FA is not required:
- requires_2fa: False
- session_id: null
- access/refresh/user: populated
 *  */
import { z } from 'zod'

/**
 * Response with JWT tokens after OAuth authentication.

When 2FA is required:
- requires_2fa: True
- session_id: UUID of 2FA verification session
- access/refresh/user: null

When 2FA is not required:
- requires_2fa: False
- session_id: null
- access/refresh/user: populated
 */
export const OAuthTokenResponseSchema = z.object({
  requires_2fa: z.boolean().optional(),
  session_id: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i).nullable().optional(),
  access: z.string().nullable().optional(),
  refresh: z.string().nullable().optional(),
  user: z.record(z.string(), z.any()).nullable().optional(),
  is_new_user: z.boolean(),
  is_new_connection: z.boolean(),
  should_prompt_2fa: z.boolean().optional(),
})

/**
 * Infer TypeScript type from Zod schema
 */
export type OAuthTokenResponse = z.infer<typeof OAuthTokenResponseSchema>