import type { FastifyInstance } from "fastify";
import { getDefaultModelId, loadModelDefinitions, toPublicModel } from "./config.js";

export const registerModelRoutes = async (app: FastifyInstance) => {
  app.get("/api/models", async () => {
    const defaultModelId = getDefaultModelId();
    const items = loadModelDefinitions().map(toPublicModel);

    return {
      default_model: items.some((model) => model.id === defaultModelId) ? defaultModelId : items[0]?.id,
      items,
    };
  });
};
