import { Injectable } from '@nestjs/common';
import { DataSource } from 'typeorm';
import { TenantAwareRepository } from '@it0/database';
import { Cluster } from '../../domain/entities/cluster.entity';

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

  async findByEnvironment(env: string): Promise<Cluster[]> {
    return this.withRepository((repo) =>
      repo.find({ where: { environment: env } as any }),
    );
  }
}
