import { Injectable } from '@nestjs/common';
import { IndexSeasonPeriodManager } from './managers/index-season-period.manager';
import { SeasonPeriodReadService } from '../../data/services/season-period-read.service';
import { SeasonPeriodEntity } from '../entities/season-period.entity';
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
import { BaseReadOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-read.orchestrator';
import { DetailSeasonPeriodManager } from './managers/detail-season-period.manager';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { IndexSeasonPeriodeItemManager } from './managers/index-season-period-item.manager';
import { ItemRateEntity } from 'src/modules/item-related/item-rate/domain/entities/item-rate.entity';
import { ItemRateReadService } from 'src/modules/item-related/item-rate/data/services/item-rate-read.service';
import { CurrentSeasonPeriodManager } from './managers/get-current-period.manager';
import { FilterSeasonPeriodDto } from '../../infrastructure/dto/filter-season-period.dto';

@Injectable()
export class SeasonPeriodReadOrchestrator extends BaseReadOrchestrator<SeasonPeriodEntity> {
  constructor(
    private indexManager: IndexSeasonPeriodManager,
    private detailManager: DetailSeasonPeriodManager,
    private indexItemManager: IndexSeasonPeriodeItemManager,
    private currentPeriodManager: CurrentSeasonPeriodManager,
    private serviceData: SeasonPeriodReadService,
    private itemServiceRead: ItemRateReadService,
  ) {
    super();
  }

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

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

  async currentPeriod(params): Promise<SeasonPeriodEntity> {
    this.currentPeriodManager.setFilterParam(params);
    this.currentPeriodManager.setService(
      this.serviceData,
      TABLE_NAME.SEASON_PERIOD,
    );
    await this.currentPeriodManager.execute();
    const data = this.currentPeriodManager.getResult();
    return data.data[0];
  }

  async indexItem(params): Promise<PaginationResponse<ItemRateEntity>> {
    this.indexItemManager.setFilterParam(params);
    this.indexItemManager.setService(
      this.itemServiceRead,
      TABLE_NAME.SEASON_PERIOD,
    );
    await this.indexItemManager.execute();
    return this.indexItemManager.getResult();
  }
}
