import { z } from 'zod';
import { oneWeekInMs } from '../../shared/utils.js';
export const queryContextInputParser = z.tuple([
    z.string(),
    z.string(),
    z.date(),
    z.date(),
]);
export const fromContext = (x) => {
    return {
        collectionName: x[0],
        project: x[1],
        startDate: x[2],
        endDate: x[3],
    };
};
export const githubQueryContextInputParser = z
    .tuple([z.date(), z.date()])
    .transform(c => [process.env.ORG_ID || 'unknown-org-id', ...c]);
export const fromGithubContext = (x) => {
    return {
        orgId: x[0],
        startDate: x[1],
        endDate: x[2],
    };
};
export const durationIndex = (startDate, field, durationMs) => ({
    $trunc: { $divide: [{ $subtract: [field, startDate] }, durationMs] },
});
export const weekIndexValue = (startDate, field) => durationIndex(startDate, field, oneWeekInMs);
