import { Injectable } from '@nestjs/common';
import { CreateTermConditionManager } from './managers/create-term-condition.manager';
import { TermConditionDataService } from '../../data/services/term-condition-data.service';
import { TermConditionEntity } from '../entities/term-condition.entity';
import { DeleteTermConditionManager } from './managers/delete-term-condition.manager';
import { UpdateTermConditionManager } from './managers/update-term-condition.manager';
import { BaseDataTransactionOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-data-transaction.orchestrator';
import { ActiveTermConditionManager } from './managers/active-term-condition.manager';
import { InactiveTermConditionManager } from './managers/inactive-term-condition.manager';
import { ConfirmTermConditionManager } from './managers/confirm-term-condition.manager';
import { STATUS } from 'src/core/strings/constants/base.constants';
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
import { BatchConfirmTermConditionManager } from './managers/batch-confirm-term-condition.manager';
import { BatchInactiveTermConditionManager } from './managers/batch-inactive-term-condition.manager';
import { BatchActiveTermConditionManager } from './managers/batch-active-term-condition.manager';
import { BatchDeleteTermConditionManager } from './managers/batch-delete-term-condition.manager';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { ChangePositionTermConditionManager } from './managers/change-position-term-condition.manager';

@Injectable()
export class TermConditionDataOrchestrator extends BaseDataTransactionOrchestrator<TermConditionEntity> {
  constructor(
    private createManager: CreateTermConditionManager,
    private updateManager: UpdateTermConditionManager,
    private deleteManager: DeleteTermConditionManager,
    private activeManager: ActiveTermConditionManager,
    private confirmManager: ConfirmTermConditionManager,
    private inactiveManager: InactiveTermConditionManager,
    private batchDeleteManager: BatchDeleteTermConditionManager,
    private batchActiveManager: BatchActiveTermConditionManager,
    private batchConfirmManager: BatchConfirmTermConditionManager,
    private batchInactiveManager: BatchInactiveTermConditionManager,
    private changePositionManager: ChangePositionTermConditionManager,
    private serviceData: TermConditionDataService,
  ) {
    super();
  }

  async changePostion(data): Promise<string> {
    this.changePositionManager.setData(data, 'sort_order');
    this.changePositionManager.setService(
      this.serviceData,
      TABLE_NAME.TERM_CONDITION,
    );
    await this.changePositionManager.execute();
    return this.changePositionManager.getResult();
  }

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

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

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