import { Injectable } from '@nestjs/common';
import { IndexItemManager } from './managers/index-item.manager';
import { ItemReadService } from '../../data/services/item-read.service';
import { ItemEntity } from '../entities/item.entity';
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
import { BaseReadOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-read.orchestrator';
import { DetailItemManager } from './managers/detail-item.manager';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { ItemRateReadService } from 'src/modules/item-related/item-rate/data/services/item-rate-read.service';
import { FilterItemRateDto } from 'src/modules/item-related/item-rate/infrastructure/dto/filter-item-rate.dto';
import { ItemRateEntity } from 'src/modules/item-related/item-rate/domain/entities/item-rate.entity';
import { IndexItemRatesManager } from './managers/index-item-rates.manager';
import { IndexItemQueueManager } from './managers/index-queue-item.manager';

@Injectable()
export class ItemReadOrchestrator extends BaseReadOrchestrator<ItemEntity> {
  constructor(
    private indexManager: IndexItemManager,
    private indexQueueManager: IndexItemQueueManager,
    private detailManager: DetailItemManager,
    private indexRateManager: IndexItemRatesManager,
    private serviceData: ItemReadService,
    private serviceItemData: ItemRateReadService,
  ) {
    super();
  }

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

  async indexQueue(params): Promise<PaginationResponse<ItemEntity>> {
    this.indexQueueManager.setFilterParam(params);
    this.indexQueueManager.setService(this.serviceData, TABLE_NAME.ITEM);
    await this.indexQueueManager.execute();
    return this.indexQueueManager.getResult();
  }

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

  async indexRate(params): Promise<PaginationResponse<ItemRateEntity>> {
    this.indexRateManager.setFilterParam(params);
    this.indexRateManager.setService(this.serviceItemData, TABLE_NAME.ITEM);
    await this.indexRateManager.execute();
    return this.indexRateManager.getResult();
  }
}
