import { Injectable } from '@nestjs/common';
import { DataSource } from 'typeorm';
import { TenantAwareRepository } from '@it0/database';
import { AgentSession } from '../../domain/entities/agent-session.entity';

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

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

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