import { Injectable } from '@nestjs/common';
import { DataSource } from 'typeorm';
import { BaseRepository } from '@edr/api-common';
import { TrainCompositionRemovalLog } from './entities/train-composition-removal-log.entity';

@Injectable()
export class TrainCompositionRemovalLogRepository extends BaseRepository<TrainCompositionRemovalLog> {
  constructor(dataSource: DataSource) {
    super(dataSource.getRepository(TrainCompositionRemovalLog));
  }

  async findByScheduleId(scheduleId: string): Promise<TrainCompositionRemovalLog[]> {
    return this.findAll({
      where: { scheduleId },
      order: { removedAt: 'DESC' },
    });
  }
}
