import { Injectable } from '@nestjs/common';
import { CreateSeasonPeriodManager } from './managers/create-season-period.manager';
import { SeasonPeriodDataService } from '../../data/services/season-period-data.service';
import { SeasonPeriodEntity } from '../entities/season-period.entity';
import { DeleteSeasonPeriodManager } from './managers/delete-season-period.manager';
import { UpdateSeasonPeriodManager } from './managers/update-season-period.manager';
import { BaseDataTransactionOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-data-transaction.orchestrator';
import { ActiveSeasonPeriodManager } from './managers/active-season-period.manager';
import { InactiveSeasonPeriodManager } from './managers/inactive-season-period.manager';
import { ConfirmSeasonPeriodManager } from './managers/confirm-season-period.manager';
import { STATUS } from 'src/core/strings/constants/base.constants';
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
import { BatchConfirmSeasonPeriodManager } from './managers/batch-confirm-season-period.manager';
import { BatchInactiveSeasonPeriodManager } from './managers/batch-inactive-season-period.manager';
import { BatchActiveSeasonPeriodManager } from './managers/batch-active-season-period.manager';
import { BatchDeleteSeasonPeriodManager } from './managers/batch-delete-season-period.manager';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { UpdateSeasonPeriodPriceManager } from './managers/update-season-period-price.manager';

@Injectable()
export class SeasonPeriodDataOrchestrator extends BaseDataTransactionOrchestrator<SeasonPeriodEntity> {
  constructor(
    private createManager: CreateSeasonPeriodManager,
    private updateManager: UpdateSeasonPeriodManager,
    private deleteManager: DeleteSeasonPeriodManager,
    private activeManager: ActiveSeasonPeriodManager,
    private confirmManager: ConfirmSeasonPeriodManager,
    private inactiveManager: InactiveSeasonPeriodManager,
    private batchDeleteManager: BatchDeleteSeasonPeriodManager,
    private batchActiveManager: BatchActiveSeasonPeriodManager,
    private batchConfirmManager: BatchConfirmSeasonPeriodManager,
    private batchInactiveManager: BatchInactiveSeasonPeriodManager,
    private updatePriceManager: UpdateSeasonPeriodPriceManager,
    private serviceData: SeasonPeriodDataService,
  ) {
    super();
  }

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

  async update(dataId, data, updatePrice = false): Promise<SeasonPeriodEntity> {
    this.updateManager.setData(dataId, {
      ...data,
      isUpdatePrice: updatePrice,
    });
    this.updateManager.setService(this.serviceData, TABLE_NAME.SEASON_PERIOD);
    await this.updateManager.execute();
    return this.updateManager.getResult();
  }

  async updatePrice(data): Promise<any> {
    this.updatePriceManager.setData(data);
    this.updatePriceManager.setService(
      this.serviceData,
      TABLE_NAME.SEASON_PERIOD,
    );
    await this.updatePriceManager.execute();
    return this.updatePriceManager.getResult();
  }

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