import { Router } from "express";
import { ok } from "../utils/http";
import type { AppServices } from "../serverContext";
import type { NormalizeRequestPayload } from "../types/normalizer";

export function buildNormalizeRouter(services: AppServices): Router {
  const router = Router();

  router.post("/api/normalize", async (req, res, next) => {
    try {
      const payload = req.body as NormalizeRequestPayload;
      const result = await services.normalizerService.normalize(payload);
      ok(res, result);
    } catch (error) {
      next(error);
    }
  });

  return router;
}
