import { makeRouter } from "../lib";
import { push } from "./push";
import { createClient } from "@supabase/supabase-js";
import { Database } from "supabase/database.types";
import { pull } from "./pull";
import { getFactsForRoots } from "./getFactsForRoots";
import { Vercel } from "@vercel/sdk";
import {
  get_domain_status,
  get_leaflet_subdomain_status,
} from "./domain_routes";
import { get_leaflet_data } from "./get_leaflet_data";
import { get_publication_data } from "./get_publication_data";
import { get_standard_site_posts } from "./get_standard_site_posts";
import { search_publication_names } from "./search_publication_names";
import { search_publication_documents } from "./search_publication_documents";
import { get_profile_data } from "./get_profile_data";
import { get_profiles } from "./get_profiles";
import { get_user_recommendations } from "./get_user_recommendations";
import { get_hot_feed } from "./get_hot_feed";
import { get_document_interactions } from "./get_document_interactions";
import { get_publication_analytics } from "./get_publication_analytics";
import { get_publication_subscribers_timeseries } from "./get_publication_subscribers_timeseries";
import { get_user_mention_services } from "./get_user_mention_services";
import { proxy_mention_search } from "./proxy_mention_search";

let supabase = createClient<Database>(
  process.env.NEXT_PUBLIC_SUPABASE_API_URL as string,
  process.env.SUPABASE_SERVICE_ROLE_KEY as string,
);

const VERCEL_TOKEN = process.env.VERCEL_TOKEN;
const vercel = new Vercel({
  bearerToken: VERCEL_TOKEN,
});
const Env = {
  supabase,
  vercel,
};
export type Env = typeof Env;
export type Routes = typeof Routes;
let Routes = [
  push,
  pull,
  getFactsForRoots,
  get_domain_status,
  get_leaflet_subdomain_status,
  get_leaflet_data,
  get_publication_data,
  get_standard_site_posts,
  search_publication_names,
  search_publication_documents,
  get_profile_data,
  get_profiles,
  get_user_recommendations,
  get_hot_feed,
  get_document_interactions,
  get_publication_analytics,
  get_publication_subscribers_timeseries,
  get_user_mention_services,
  proxy_mention_search,
];
export async function POST(
  req: Request,
  { params }: { params: Promise<{ command: string }> },
) {
  let p = await params;
  let router = makeRouter(Routes);
  return router(p.command, req, Env);
}
