import { Injectable } from '@nestjs/common';
import { DataSource } from 'typeorm';
import { TenantAwareRepository } from '@it0/database';
import { StandingOrderExecution } from '../../domain/entities/standing-order-execution.entity';

@Injectable()
export class StandingOrderExecutionRepository extends TenantAwareRepository<StandingOrderExecution> {
  constructor(dataSource: DataSource) {
    super(dataSource, StandingOrderExecution);
  }

  async findByOrderId(orderId: string): Promise<StandingOrderExecution[]> {
    return this.withRepository((repo) =>
      repo.find({ where: { orderId } as any }),
    );
  }
}
