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

/* /v1/credential/:id/secure-values */
export default createRoute(
  "get",
  ["/credentials/:id/secure-values"],

  async (c) => {
    const credential = await credentials.fetch(c.req.param("id"));
    const secureValues = await credential.readAllSecureValues();

    const response = apiResponse.successful(
      "Secure Values Fetched Successfully!",
      secureValues,
    );
    return c.json(response, response.status as ContentfulStatusCode);
  },
  authMiddleware({
    permissions: ["credential.fetch", "credential.secure_values.read"],
  }),
);
