import { Service } from 'typedi';
import { PortsDI } from '../../../../../config/portsDI';
import ShiftAssignedDayRepositoryPort from '../../../infrastructure/ports/shiftManagement/shiftAssignedDayRepositoryPort';

/**
 * Today the only source of occurrences is the materialized assignment grid
 * (`ShiftAssignedShift.shiftRotationId`). When recurrence lands, a config-derived source for
 * far-future ranges that were never materialized is unioned in *inside this service* — callers
 * (e.g. the calendar filter) do not change.
 */
@Service()
export class RotationOccurrenceService {
    constructor(@PortsDI(ShiftAssignedDayRepositoryPort) private readonly shiftAssignedDayRepository: ShiftAssignedDayRepositoryPort) {}

    /**
     * Ids of users who have at least one shift (WORK or REST) originating from any of the given
     * rotations within `[startDate, endDate]`.
     */
    public userIdsWithRotationInRange = async (instanceId: number, rotationIds: string[], startDate: string, endDate: string): Promise<number[]> => {
        return this.shiftAssignedDayRepository.getUserIdsWithRotationInRange(instanceId, rotationIds, startDate, endDate);
    };
}
