"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BulkCreateTraces = void 0;
class BulkCreateTraces {
    traceRepository;
    projectRepository;
    constructor(traceRepository, projectRepository) {
        this.traceRepository = traceRepository;
        this.projectRepository = projectRepository;
    }
    async execute(tracesData) {
        if (!tracesData || tracesData.length === 0) {
            throw new Error('No trace data provided');
        }
        // Validate each trace data
        for (const traceData of tracesData) {
            if (!traceData.projectId || !traceData.name || !traceData.startTime) {
                throw new Error('Missing required fields in trace data: projectId, name, startTime');
            }
        }
        // Validate that all referenced projects exist
        const uniqueProjectIds = [...new Set(tracesData.map(trace => trace.projectId))];
        for (const projectId of uniqueProjectIds) {
            const project = await this.projectRepository.getProjectById(projectId);
            if (!project) {
                throw new Error(`Project with ID '${projectId}' does not exist. Please create the project first before adding traces.`);
            }
        }
        return await this.traceRepository.bulkTraceInsert(tracesData);
    }
}
exports.BulkCreateTraces = BulkCreateTraces;
//# sourceMappingURL=bulkCreateTraces.js.map