// SPDX-License-Identifier: AGPL-3.0-or-later

import type {ICacheService} from '@pkgs/cache/src/ICacheService';
import type {IEmailService} from '@pkgs/email/src/IEmailService';
import type {IRateLimitService} from '@pkgs/rate_limit/src/IRateLimitService';
import type {IWorkerService} from '@pkgs/worker/src/contracts/IWorkerService';
import type {Hono} from 'hono';
import type {ApiContext} from '../ApiContext';
import type {AdminService} from '../admin/AdminService';
import type {AdminApiKeyService} from '../admin/services/AdminApiKeyService';
import type {AdminArchiveService} from '../admin/services/AdminArchiveService';
import type {AuthRequestService} from '../auth/AuthRequestService';
import type {DesktopHandoffService} from '../auth/services/DesktopHandoffService';
import type {SsoService} from '../auth/services/SsoService';
import type {ApplicationID, UserID} from '../BrandedTypes';
import type {IBlueskyOAuthService} from '../bluesky/IBlueskyOAuthService';
import type {IChannelRepository} from '../channel/IChannelRepository';
import type {ChannelRequestService} from '../channel/services/ChannelRequestService';
import type {ChannelService} from '../channel/services/ChannelService';
import type {MessageRequestService} from '../channel/services/message/MessageRequestService';
import type {StreamPreviewService} from '../channel/services/StreamPreviewService';
import type {StreamService} from '../channel/services/StreamService';
import type {ConnectionRequestService} from '../connection/ConnectionRequestService';
import type {ConnectionService} from '../connection/ConnectionService';
import type {NcmecSubmissionService} from '../csam/NcmecSubmissionService';
import type {DonationService} from '../donation/DonationService';
import type {DownloadService} from '../download/DownloadService';
import type {FavoriteMemeRequestService} from '../favorite_meme/FavoriteMemeRequestService';
import type {FavoriteMemeService} from '../favorite_meme/FavoriteMemeService';
import type {GatewayRequestService} from '../gateway/GatewayRequestService';
import type {GifService} from '../gif/GifService';
import type {IGuildDiscoveryService} from '../guild/services/GuildDiscoveryService';
import type {GuildService} from '../guild/services/GuildService';
import type {EmbedService} from '../infrastructure/EmbedService';
import type {EntityAssetService} from '../infrastructure/EntityAssetService';
import type {ErrorI18nService} from '../infrastructure/ErrorI18nService';
import type {IGatewayService} from '../infrastructure/IGatewayService';
import type {IMediaService} from '../infrastructure/IMediaService';
import type {ISnowflakeService} from '../infrastructure/ISnowflakeService';
import type {IStorageService} from '../infrastructure/IStorageService';
import type {KVActivityTracker} from '../infrastructure/KVActivityTracker';
import type {LiveKitWebhookService} from '../infrastructure/LiveKitWebhookService';
import type {UserCacheService} from '../infrastructure/UserCacheService';
import type {InstanceConfigRepository} from '../instance/InstanceConfigRepository';
import type {SingleCommunityService} from '../instance/SingleCommunityService';
import type {InviteRequestService} from '../invite/InviteRequestService';
import type {InviteService} from '../invite/InviteService';
import type {LimitConfigService} from '../limits/LimitConfigService';
import type {RequestCache} from '../middleware/RequestCacheMiddleware';
import type {AuthSession} from '../models/AuthSession';
import type {User} from '../models/User';
import type {ApplicationService} from '../oauth/ApplicationService';
import type {BotAuthService} from '../oauth/BotAuthService';
import type {OAuth2ApplicationsRequestService} from '../oauth/OAuth2ApplicationsRequestService';
import type {OAuth2RequestService} from '../oauth/OAuth2RequestService';
import type {OAuth2Service} from '../oauth/OAuth2Service';
import type {IApplicationRepository} from '../oauth/repositories/IApplicationRepository';
import type {IOAuth2TokenRepository} from '../oauth/repositories/IOAuth2TokenRepository';
import type {ReadStateRequestService} from '../read_state/ReadStateRequestService';
import type {ReadStateService} from '../read_state/ReadStateService';
import type {ReportRequestService} from '../report/ReportRequestService';
import type {ReportService} from '../report/ReportService';
import type {RpcService} from '../rpc/RpcService';
import type {SearchService} from '../search/SearchService';
import type {StripeService} from '../stripe/StripeService';
import type {AgeVerificationService} from '../stripe/services/AgeVerificationService';
import type {ThemeService} from '../theme/ThemeService';
import type {EntranceSoundPlayService} from '../user/entrance_sound/EntranceSoundPlayService';
import type {EntranceSoundService} from '../user/entrance_sound/EntranceSoundService';
import type {IUserRepository} from '../user/IUserRepository';
import type {EmailChangeService} from '../user/services/EmailChangeService';
import type {PasswordChangeService} from '../user/services/PasswordChangeService';
import type {UserAccountRequestService} from '../user/services/UserAccountRequestService';
import type {UserActivityBuffer} from '../user/services/UserActivityBuffer';
import type {UserAuthRequestService} from '../user/services/UserAuthRequestService';
import type {UserChannelRequestService} from '../user/services/UserChannelRequestService';
import type {UserContactChangeLogService} from '../user/services/UserContactChangeLogService';
import type {UserContentRequestService} from '../user/services/UserContentRequestService';
import type {UserRelationshipRequestService} from '../user/services/UserRelationshipRequestService';
import type {UserService} from '../user/services/UserService';
import type {ClientIpResolution} from '../utils/RequestClientIp';
import type {SweegoWebhookService} from '../webhook/SweegoWebhookService';
import type {WebhookRequestService} from '../webhook/WebhookRequestService';
import type {WebhookService} from '../webhook/WebhookService';
import type {WorkerTaskName} from '../worker/WorkerLaneConfig';

export interface HonoEnv {
	Variables: {
		apiContext: ApiContext;
		user: User;
		requestId?: string;
		clientIpResolution?: ClientIpResolution;
		responseSchema: unknown;
		adminService: AdminService;
		adminArchiveService: AdminArchiveService;
		adminApiKeyService: AdminApiKeyService;
		adminApiKey?: {
			keyId: bigint;
			createdById: UserID;
		};
		adminApiKeyAcls: Set<string> | null;
		adminUserId: UserID;
		adminUserAcls: Set<string>;
		authTokenType?: 'session' | 'bearer' | 'bot' | 'admin_api_key';
		authViaCookie?: boolean;
		authToken?: string;
		authUserId?: string;
		oauthBearerAllowed?: boolean;
		oauthBearerToken?: string;
		oauthBearerApplicationId?: ApplicationID;
		oauthBearerScopes?: Set<string>;
		oauthBearerUserId?: UserID;
		auditLogReason: string | null;
		authRequestService: AuthRequestService;
		ssoService: SsoService;
		authSession: AuthSession;
		desktopHandoffService: DesktopHandoffService;
		cacheService: ICacheService;
		channelService: ChannelService;
		channelRequestService: ChannelRequestService;
		messageRequestService: MessageRequestService;
		channelRepository: IChannelRepository;
		connectionService: ConnectionService;
		connectionRequestService: ConnectionRequestService;
		blueskyOAuthService: IBlueskyOAuthService;
		donationService: DonationService;
		downloadService: DownloadService;
		streamPreviewService: StreamPreviewService;
		streamService: StreamService;
		emailService: IEmailService;
		emailChangeService: EmailChangeService;
		passwordChangeService: PasswordChangeService;
		embedService: EmbedService;
		entityAssetService: EntityAssetService;
		entranceSoundService: EntranceSoundService;
		entranceSoundPlayService: EntranceSoundPlayService;
		favoriteMemeService: FavoriteMemeService;
		favoriteMemeRequestService: FavoriteMemeRequestService;
		gatewayService: IGatewayService;
		gatewayRequestService: GatewayRequestService;
		discoveryService: IGuildDiscoveryService;
		guildService: GuildService;
		inviteService: InviteService;
		inviteRequestService: InviteRequestService;
		liveKitWebhookService?: LiveKitWebhookService;
		mediaService: IMediaService;
		rateLimitService: IRateLimitService;
		readStateService: ReadStateService;
		readStateRequestService: ReadStateRequestService;
		kvActivityTracker: KVActivityTracker;
		userActivityBuffer: UserActivityBuffer;
		reportService: ReportService;
		reportRequestService: ReportRequestService;
		contactChangeLogService: UserContactChangeLogService;
		ncmecSubmissionService: NcmecSubmissionService;
		requestCache: RequestCache;
		rpcService: RpcService;
		searchService: SearchService;
		snowflakeService: ISnowflakeService;
		storageService: IStorageService;
		gifService: GifService;
		themeService: ThemeService;
		userCacheService: UserCacheService;
		userRepository: IUserRepository;
		userService: UserService;
		userAccountRequestService: UserAccountRequestService;
		userAuthRequestService: UserAuthRequestService;
		userChannelRequestService: UserChannelRequestService;
		userContentRequestService: UserContentRequestService;
		userRelationshipRequestService: UserRelationshipRequestService;
		sweegoWebhookService: SweegoWebhookService;
		webhookService: WebhookService;
		webhookRequestService: WebhookRequestService;
		workerService: IWorkerService<WorkerTaskName>;
		stripeService: StripeService;
		ageVerificationService: AgeVerificationService;
		applicationService: ApplicationService;
		oauth2Service: OAuth2Service;
		oauth2RequestService: OAuth2RequestService;
		oauth2ApplicationsRequestService: OAuth2ApplicationsRequestService;
		applicationRepository: IApplicationRepository;
		oauth2TokenRepository: IOAuth2TokenRepository;
		botAuthService: BotAuthService;
		sudoModeValid: boolean;
		sudoModeToken: string | null;
		instanceConfigRepository: InstanceConfigRepository;
		singleCommunityService: SingleCommunityService;
		limitConfigService: LimitConfigService;
		requestLocale: string;
		errorI18nService: ErrorI18nService;
		channelUpdateType?: number;
	};
}

export type HonoApp = Hono<HonoEnv>;
