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

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

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

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