import { Injectable } from '@nestjs/common';
import { CreateItemRateManager } from './managers/create-item-rate.manager';
import { ItemRateDataService } from '../../data/services/item-rate-data.service';
import { ItemRateEntity } from '../entities/item-rate.entity';
import { DeleteItemRateManager } from './managers/delete-item-rate.manager';
import { UpdateItemRateManager } from './managers/update-item-rate.manager';
import { BaseDataOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-data.orchestrator';
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
import { BatchDeleteItemRateManager } from './managers/batch-delete-item-rate.manager';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';

@Injectable()
export class ItemRateDataOrchestrator extends BaseDataOrchestrator<ItemRateEntity> {
  constructor(
    private createManager: CreateItemRateManager,
    private updateManager: UpdateItemRateManager,
    private deleteManager: DeleteItemRateManager,
    private batchDeleteManager: BatchDeleteItemRateManager,
    private serviceData: ItemRateDataService,
  ) {
    super();
  }

  async create(data): Promise<ItemRateEntity> {
    this.createManager.setData(data);
    this.createManager.setService(this.serviceData, TABLE_NAME.ITEM_RATE);
    await this.createManager.execute();
    return this.createManager.getResult();
  }

  async update(dataId, data): Promise<ItemRateEntity> {
    this.updateManager.setData(dataId, data);
    this.updateManager.setService(this.serviceData, TABLE_NAME.ITEM_RATE);
    await this.updateManager.execute();
    return this.updateManager.getResult();
  }

  async delete(dataId): Promise<string> {
    this.deleteManager.setData(dataId);
    this.deleteManager.setService(this.serviceData, TABLE_NAME.ITEM_RATE);
    await this.deleteManager.execute();
    return this.deleteManager.getResult();
  }

  async batchDelete(dataIds: string[]): Promise<BatchResult> {
    this.batchDeleteManager.setData(dataIds);
    this.batchDeleteManager.setService(this.serviceData, TABLE_NAME.ITEM_RATE);
    await this.batchDeleteManager.execute();
    return this.batchDeleteManager.getResult();
  }
}
