import type { ITeamRatingEventRepository } from '@core/racing/domain/repositories/ITeamRatingEventRepository'; import type { ITeamRatingRepository } from '@core/racing/domain/repositories/ITeamRatingRepository'; import { TeamRatingSnapshotCalculator } from '@core/racing/domain/services/TeamRatingSnapshotCalculator'; /** * Use Case: RecomputeTeamRatingSnapshotUseCase * * Recalculates a team's rating snapshot from all events in the ledger. * Used for data migration, correction of calculation logic, or audit purposes. * Mirrors the RecomputeUserRatingSnapshotUseCase pattern. */ export class RecomputeTeamRatingSnapshotUseCase { constructor( private readonly ratingEventRepository: ITeamRatingEventRepository, private readonly ratingRepository: ITeamRatingRepository, ) {} /** * Execute the use case for a specific team * * @param teamId - The team ID to recompute * @returns The recomputed snapshot */ async execute(teamId: string): Promise { // Get all events for the team const events = await this.ratingEventRepository.getAllByTeamId(teamId); // Calculate snapshot from all events const snapshot = TeamRatingSnapshotCalculator.calculate(teamId, events); // Save the recomputed snapshot await this.ratingRepository.save(snapshot); } /** * Execute the use case for all teams */ async executeForAllTeams(): Promise { // Get all unique team IDs from events // This would typically query for all distinct teamIds in the events table // For now, we'll use a simpler approach - recompute for teams that have snapshots // In a real implementation, you might have a separate method to get all team IDs // Note: This is a simplified implementation // In production, you'd want to batch this and handle errors per team throw new Error('executeForAllTeams not implemented - needs team ID discovery'); } }