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

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

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

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