import type { APIEvent } from "@solidjs/start/server"
import { handler } from "~/routes/zen/util/handler"
import { parseGoogleVariant } from "~/routes/zen/util/variant"

export function POST(input: APIEvent) {
  return handler(input, {
    format: "google",
    modelList: "full",
    parseApiKey: (headers: Headers) => headers.get("x-goog-api-key") ?? undefined,
    parseModel: (url: string, _body: any) => url.split("/").pop()?.split(":")?.[0] ?? "",
    parseVariant: (url: string, body: any) => parseGoogleVariant(body),
    parseIsStream: (url: string, _body: any) =>
      // ie. url: https://opencode.ai/zen/v1/models/gemini-3-pro:streamGenerateContent?alt=sse'
      url.split("/").pop()?.split(":")?.[1]?.startsWith("streamGenerateContent") ?? false,
  })
}
