class PreservationReportRepository {

    public PreservationStatsModel stats(String processId, int tenantId) {
        Bson eqProcessId = eq(PROCESS_ID, processId);
        Bson eqTenant = eq(TENANT, tenantId);

        int nbUnits = getUnitAndObjectGroupStats(and(eqProcessId, eqTenant), UNIT_ID);
        int nbObjectGroups = getUnitAndObjectGroupStats(and(eqProcessId, eqTenant), OBJECT_GROUP_ID);
        int nbStatusKos = getStats(and(eqTenant, eqProcessId, eq(STATUS, KO.name())), STATUS);
        int nbStatusWarning = getStats(and(eqTenant, eqProcessId, eq(STATUS, WARNING.name())), STATUS);

        int nbActionsAnaylse = getStats(and(eqTenant, eqProcessId, eq(ACTION, ANALYSE.name())), ACTION);
        int nbActionsGenerate = getStats(and(eqTenant, eqProcessId, eq(ACTION, GENERATE.name())), ACTION);
        int nbActionsIdentify = getStats(and(eqTenant, eqProcessId, eq(ACTION, IDENTIFY.name())), ACTION);
        int nbActionsExtract = getStats(and(eqTenant, eqProcessId, eq(ACTION, EXTRACT.name())), ACTION);

        Spliterator<SimpleEntry<String, Integer>> mapAnalyseResult = nbActionsAnaylse > 0
            ? collection.aggregate(
            Arrays.asList(
                match(and(eqTenant, eqProcessId)),
                project(include("analyseResult")),
                group("$" + ANALYSE_RESULT, sum("count", 1)))
        ).allowDiskUse(true)
            .batchSize(VitamConfiguration.getBatchSize())
            .map(d -> new SimpleEntry<>(d.getString("_id"), d.get("count", Integer.class)))
            .spliterator()
            : Spliterators.emptySpliterator();

        Map<String, Integer> analyseResults = StreamSupport.stream(mapAnalyseResult, false)
            .collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue));

        return new PreservationStatsModel(
            nbUnits,
            nbObjectGroups,
            nbStatusKos,
            nbActionsAnaylse,
            nbActionsGenerate,
            nbActionsIdentify,
            nbActionsExtract,
            analyseResults,
            nbStatusWarning);
    }

    @VisibleForTesting public  PreservationReportRepository(MongoDbAccess mongoDbAccess, String collectionName);
    public  PreservationReportRepository(MongoDbAccess mongoDbAccess);

}