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

// /v1/user/@me
export default createRoute(
  "get",
  ["/@me"],
  async (c) => {
    const gatedData = await processObjectValuePerms(
      c.get("user")?.toJson(),
      "obj.user",
      c.get("user"),
    );

    const response = apiResponse.successful("Fetched user.", gatedData);
    return c.json(response, response.status as ContentfulStatusCode);
  },
  authMiddleware({ scopes: ["user.read"] }),
);
