import { Injectable } from '@nestjs/common';
import { IndexUserManager } from './managers/index-user.manager';
import { UserReadService } from '../../data/services/user-read.service';
import { UserEntity } from '../entities/user.entity';
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
import { BaseReadOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-read.orchestrator';
import { DetailUserManager } from './managers/detail-user.manager';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';

@Injectable()
export class UserReadOrchestrator extends BaseReadOrchestrator<UserEntity> {
  constructor(
    private indexManager: IndexUserManager,
    private detailManager: DetailUserManager,
    private serviceData: UserReadService,
  ) {
    super();
  }

  async index(params): Promise<PaginationResponse<UserEntity>> {
    this.indexManager.setFilterParam(params);
    this.indexManager.setService(this.serviceData, TABLE_NAME.USER);
    await this.indexManager.execute();
    return this.indexManager.getResult();
  }

  async detail(dataId: string): Promise<UserEntity> {
    this.detailManager.setData(dataId);
    this.detailManager.setService(this.serviceData, TABLE_NAME.USER);
    await this.detailManager.execute();
    return this.detailManager.getResult();
  }
}
