import { Injectable } from '@nestjs/common';
import { IndexTimeGroupManager } from './managers/index-time-group.manager';
import { TimeGroupReadService } from '../../data/services/time-group-read.service';
import { TimeGroupEntity } from '../entities/time-group.entity';
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
import { BaseReadOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-read.orchestrator';
import { DetailTimeGroupManager } from './managers/detail-time-group.manager';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { IndexPublicTimeGroupManager } from './managers/index-public-time-group.manager';

@Injectable()
export class TimeGroupReadOrchestrator extends BaseReadOrchestrator<TimeGroupEntity> {
  constructor(
    private indexManager: IndexTimeGroupManager,
    private indexPublicManager: IndexPublicTimeGroupManager,
    private detailManager: DetailTimeGroupManager,
    private serviceData: TimeGroupReadService,
  ) {
    super();
  }

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

  async indexPublic(params): Promise<PaginationResponse<TimeGroupEntity>> {
    this.indexPublicManager.setFilterParam(params);
    this.indexPublicManager.setService(
      this.serviceData,
      TABLE_NAME.TIME_GROUPS,
    );
    await this.indexPublicManager.execute();
    return this.indexPublicManager.getResult();
  }

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