import { verifyKey } from "discord-interactions";
import { createDiscordAdapter } from "./adapters/discord/index.ts";
import { createTelegramAdapter } from "./adapters/telegram/index.ts";
import { handleTelegramWebhookRequest } from "./adapters/telegram/webhook.ts";
import { createSlackAdapter } from "./adapters/slack/index.ts";
import { handleSlackCommandRequest } from "./adapters/slack/webhook.ts";
import { buildCommandConfig } from "./core/config.ts";
import { handleInteraction, type DiscordInteraction } from "./adapters/discord/interactions.ts";
import { createAddress, getCounters } from "./core/db.ts";
import { createDispatcher } from "./core/dispatch.ts";
import { handleInboundEmail } from "./core/email.ts";
import { sendExpiryWarnings } from "./core/expiry-warning.ts";
import type { MailAdapter, OwnerRef } from "./core/types.ts";
import { renderCounterPage } from "./counter-page.ts";
import { createMailtmAddress } from "./receivers/mailtm/address.ts";
import { runMailtmCleanup } from "./receivers/mailtm/cleanup.ts";
import { pollOnce } from "./receivers/mailtm/poller.ts";
import { createD1Executor } from "./storage/d1.ts";
import pkg from "../package.json";
// One Worker, two modes, picked by whether DISPOSABLE_DOMAIN is set:
//
// set -> your own domain. Mail arrives through Email Routing's catch-all
// hitting email() below. Needs DNS and a zone.
// unset -> mail.tm. Addresses are provisioned on mail.tm's domain and
// their API is polled on a cron instead, no domain, no DNS, no
// Email Routing. email() is never invoked because nothing routes
// mail here.
//
// Everything else (commands, storage, delivery, cleanup, the status page) is
// identical between them, which is why this is a runtime branch rather than
// two entrypoints to keep in sync.
export interface Env {
DB: D1Database;
// Optional: leave unset to run in mail.tm mode.
DISPOSABLE_DOMAIN?: string;
ADAPTERS: string;
DISCORD_TOKEN: string;
DISCORD_PUBLIC_KEY: string;
DISCORD_APPLICATION_ID: string;