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

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

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

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