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

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

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