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

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

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