import { Injectable } from '@nestjs/common';
import { DataSource } from 'typeorm';
import { TenantAwareRepository } from '@it0/database';
import { ApprovalRequest } from '../../domain/entities/approval-request.entity';

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

  async findPending(): Promise<ApprovalRequest[]> {
    return this.withRepository((repo) =>
      repo.find({ where: { status: 'pending' } as any }),
    );
  }

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