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

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

  async findActive(): Promise<AlertRule[]> {
    return this.withRepository((repo) =>
      repo.find({ where: { isActive: true } as any }),
    );
  }
}
