import { All, Body, Controller, Req } from "@nestjs/common";
import type { Request } from "express";

import { AiProxyService } from "./ai-proxy.service";

@Controller("ai-engine")
export class AiProxyController {
  constructor(private readonly aiProxyService: AiProxyService) {}

  @All("*path")
  proxy(@Req() request: Request, @Body() body: unknown) {
    return this.aiProxyService.proxy({
      method: request.method,
      originalUrl: request.originalUrl,
      query: request.query as Record<string, unknown>,
      body,
      acceptLanguage: request.headers["accept-language"],
    });
  }
}
