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

@Injectable()
export class NewsReadOrchestrator extends BaseReadOrchestrator<NewsEntity> {
  constructor(
    private indexManager: IndexNewsManager,
    private detailManager: DetailNewsManager,
    private serviceData: NewsReadService,
  ) {
    super();
  }

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

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