import { Injectable } from '@nestjs/common';
import { DataSource } from 'typeorm';
import { TenantAwareRepository } from '@it0/database';
import { AlertEvent } from '../../domain/entities/alert-event.entity';

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

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

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