import { createRoute } from "../../../../../modules/api-utils/createRoute";
import { opportunities } from "../../../../../managers/opportunities";
import { apiResponse } from "../../../../../modules/api-utils/apiResponse";
import { ContentfulStatusCode } from "hono/utils/http-status";
import { authMiddleware } from "../../../../middleware/authorization";

/* GET /v1/sales/opportunities/opportunity/:identifier/quotes/narrative */
export default createRoute(
  "get",
  ["/opportunities/opportunity/:identifier/quotes/narrative"],
  async (c) => {
    const identifier = c.req.param("identifier");
    const item = await opportunities.fetchRecord(identifier);
    const quoteNarrative = await item.fetchQuoteNarrative();

    const response = apiResponse.successful(
      "Quote narrative fetched successfully!",
      {
        quoteNarrative,
      }
    );
    return c.json(response, response.status as ContentfulStatusCode);
  },
  authMiddleware({ permissions: ["sales.opportunity.fetch"] })
);
