import { Injectable } from '@nestjs/common';
import { CreateTaxManager } from './managers/create-tax.manager';
import { TaxDataService } from '../../data/services/tax-data.service';
import { TaxEntity } from '../entities/tax.entity';
import { DeleteTaxManager } from './managers/delete-tax.manager';
import { UpdateTaxManager } from './managers/update-tax.manager';
import { BaseDataTransactionOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-data-transaction.orchestrator';
import { ActiveTaxManager } from './managers/active-tax.manager';
import { InactiveTaxManager } from './managers/inactive-tax.manager';
import { ConfirmTaxManager } from './managers/confirm-tax.manager';
import { STATUS } from 'src/core/strings/constants/base.constants';
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
import { BatchConfirmTaxManager } from './managers/batch-confirm-tax.manager';
import { BatchInactiveTaxManager } from './managers/batch-inactive-tax.manager';
import { BatchActiveTaxManager } from './managers/batch-active-tax.manager';
import { BatchDeleteTaxManager } from './managers/batch-delete-tax.manager';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { SalesPriceFormulaReadService } from 'src/modules/transaction/sales-price-formula/data/services/sales-price-formula-read.service';

@Injectable()
export class TaxDataOrchestrator extends BaseDataTransactionOrchestrator<TaxEntity> {
  constructor(
    private createManager: CreateTaxManager,
    private updateManager: UpdateTaxManager,
    private deleteManager: DeleteTaxManager,
    private activeManager: ActiveTaxManager,
    private confirmManager: ConfirmTaxManager,
    private inactiveManager: InactiveTaxManager,
    private batchDeleteManager: BatchDeleteTaxManager,
    private batchActiveManager: BatchActiveTaxManager,
    private batchConfirmManager: BatchConfirmTaxManager,
    private batchInactiveManager: BatchInactiveTaxManager,
    private serviceData: TaxDataService,
    private formulaServiceData: SalesPriceFormulaReadService,
  ) {
    super();
  }

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

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

  async delete(dataId): Promise<string> {
    this.deleteManager.setData(dataId);
    this.deleteManager.setService(
      this.serviceData,
      TABLE_NAME.TAX,
      this.formulaServiceData,
    );
    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.TAX,
      this.formulaServiceData,
    );
    await this.batchDeleteManager.execute();
    return this.batchDeleteManager.getResult();
  }

  async active(dataId): Promise<string> {
    this.activeManager.setData(dataId, STATUS.ACTIVE);
    this.activeManager.setService(this.serviceData, TABLE_NAME.TAX);
    await this.activeManager.execute();
    return this.activeManager.getResult();
  }

  async batchActive(dataIds: string[]): Promise<BatchResult> {
    this.batchActiveManager.setData(dataIds, STATUS.ACTIVE);
    this.batchActiveManager.setService(this.serviceData, TABLE_NAME.TAX);
    await this.batchActiveManager.execute();
    return this.batchActiveManager.getResult();
  }

  async confirm(dataId): Promise<string> {
    this.confirmManager.setData(dataId, STATUS.ACTIVE);
    this.confirmManager.setService(this.serviceData, TABLE_NAME.TAX);
    await this.confirmManager.execute();
    return this.confirmManager.getResult();
  }

  async batchConfirm(dataIds: string[]): Promise<BatchResult> {
    this.batchConfirmManager.setData(dataIds, STATUS.ACTIVE);
    this.batchConfirmManager.setService(this.serviceData, TABLE_NAME.TAX);
    await this.batchConfirmManager.execute();
    return this.batchConfirmManager.getResult();
  }

  async inactive(dataId): Promise<string> {
    this.inactiveManager.setData(dataId, STATUS.INACTIVE);
    this.inactiveManager.setService(
      this.serviceData,
      TABLE_NAME.TAX,
      this.formulaServiceData,
    );
    await this.inactiveManager.execute();
    return this.inactiveManager.getResult();
  }

  async batchInactive(dataIds: string[]): Promise<BatchResult> {
    this.batchInactiveManager.setData(dataIds, STATUS.INACTIVE);
    this.batchInactiveManager.setService(
      this.serviceData,
      TABLE_NAME.TAX,
      this.formulaServiceData,
    );
    await this.batchInactiveManager.execute();
    return this.batchInactiveManager.getResult();
  }
}
