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/count */
export default createRoute(
    "get",
    ["/count"],
    async (c) => {
        const count = await timeEntries.count();

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

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