import type { S3Client } from "@aws-sdk/client-s3";
import type { StripeSync } from "@supabase/stripe-sync-engine";
import type { SupabaseClient, User } from "@supabase/supabase-js";
import type { Hono } from "hono";
import type { Transporter } from "nodemailer";
import type { StreamChat } from "stream-chat";
import type Stripe from "stripe";

/**
 * Base environment variables available across all routes
 */
export type BaseEnv = {
  Variables: {
    supabase: SupabaseClient;
    streamServerClient: StreamChat;
    s3_client: S3Client;
    transporter: Transporter;
    stripe: Stripe;
    stripeSync: StripeSync;
  };
};

/**
 * Environment with authenticated user
 */
export type AuthEnv = BaseEnv & {
  Variables: BaseEnv["Variables"] & {
    user: User;
  };
};

/**
 * Environment with optional authentication (may be null)
 */
export type MaybeAuthEnv = BaseEnv & {
  Variables: BaseEnv["Variables"] & {
    user: User | null;
  };
};

/**
 * Type helper to extract the app type from a Hono instance
 */
export type ExtractEnv<T> = T extends Hono<infer E> ? E : never;
