"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getJobStatusDetails = getJobStatusDetails;
const drizzle_orm_1 = require("drizzle-orm");
const database_1 = require("../../../database");
const tables_1 = require("../../../database/tables");
/**
 * Returns { evalResultsCount } for a given testRunId (jobId), or 0 if not found.
 */
async function getJobStatusDetails(testRunId) {
    const db = (0, database_1.getDb)();
    // Single query with left joins
    // 1. Find the test run
    // 2. Left join testRunsToEvalsTable on testRunId
    // 3. Left join evalResultsTable on evalId
    // 4. Count evalResultsTable rows for the joined evalId
    const result = await db
        .select({ evalResultsCount: (0, drizzle_orm_1.sql) `count(${tables_1.evalResultsTable.id})` })
        .from(tables_1.testRunsTable)
        .leftJoin(tables_1.testRunsToEvalsTable, (0, drizzle_orm_1.eq)(tables_1.testRunsTable.id, tables_1.testRunsToEvalsTable.testRunId))
        .leftJoin(tables_1.evalResultsTable, (0, drizzle_orm_1.eq)(tables_1.testRunsToEvalsTable.evalId, tables_1.evalResultsTable.evalId))
        .where((0, drizzle_orm_1.eq)(tables_1.testRunsTable.id, testRunId));
    return { evalResultsCount: Number(result[0]?.evalResultsCount ?? 0) };
}
//# sourceMappingURL=get-job-status-details.js.map