"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getProjectApplicationsCount = void 0;
const drizzle_orm_1 = require("drizzle-orm");
const database_1 = require("../../../database");
const tables_1 = require("../../../database/tables");
const logger_1 = __importDefault(require("../../../logger"));
const getProjectApplicationsCount = async (req, res) => {
    try {
        const { projectId } = req.params;
        if (!projectId) {
            res.status(400).json({
                success: false,
                message: 'Project ID is required',
            });
            return;
        }
        const db = await (0, database_1.getDb)();
        // Get total count of applications for the specific project (excluding archived)
        const result = await db
            .select({ count: (0, drizzle_orm_1.sql) `count(*)` })
            .from(tables_1.applicationsTable)
            .where((0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(tables_1.applicationsTable.projectId, projectId), (0, drizzle_orm_1.sql) `is_archived = false`));
        const totalCount = result[0]?.count || 0;
        res.json({
            success: true,
            data: {
                count: totalCount,
                projectId,
            },
        });
    }
    catch (error) {
        logger_1.default.error(`Error fetching project applications count: ${error}`);
        res.status(500).json({
            success: false,
            message: 'Failed to fetch project applications count',
        });
    }
};
exports.getProjectApplicationsCount = getProjectApplicationsCount;
//# sourceMappingURL=get-project-applications-count.js.map