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

/* GET /v1/time-entry/time-entries/:identifier */
export default createRoute(
    "get",
    ["/time-entries/:identifier"],
    async (c) => {
        const entry = await timeEntries.fetch(c.req.param("identifier"));

        const response = apiResponse.successful(
            "Time entry fetched successfully!",
            entry.toJson(),
        );

        return c.json(response, response.status as ContentfulStatusCode);
    },
    authMiddleware({ permissions: ["time-entry.fetch"] }),
);
