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

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

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