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";

/* DELETE /v1/credential/credentials/:id/sub-credentials/:subId */
export default createRoute(
  "delete",
  ["/credentials/:id/sub-credentials/:subId"],

  async (c) => {
    const parentId = c.req.param("id");
    const subId = c.req.param("subId");

    await credentials.removeSubCredential(parentId, subId);

    const response = apiResponse.successful(
      "Sub-Credential Removed Successfully!",
      null,
    );
    return c.json(response, response.status as ContentfulStatusCode);
  },
  authMiddleware({
    permissions: ["credential.fetch", "credential.sub_credentials.delete"],
  }),
);
