import { Injectable } from '@nestjs/common';
import { BaseUpdateManager } from 'src/core/modules/domain/usecase/managers/base-update.manager';
import {
  EventTopics,
  columnUniques,
  validateRelations,
} from 'src/core/strings/constants/interface.constants';
import { SalesPriceFormulaModel } from 'src/modules/transaction/sales-price-formula/data/models/sales-price-formula.model';
import { ProfitShareFormulaUpdatedEvent } from '../../entities/event/profit-share-formula-updated.event';
import { SalesPriceFormulaEntity } from 'src/modules/transaction/sales-price-formula/domain/entities/sales-price-formula.entity';
// import { In } from 'typeorm';
// import { STATUS } from 'src/core/strings/constants/base.constants';
// import { calculateProfitFormula } from 'src/modules/transaction/sales-price-formula/domain/usecases/managers/helpers/calculation-formula.helper';

@Injectable()
export class UpdateProfitShareFormulaManager extends BaseUpdateManager<SalesPriceFormulaEntity> {
  async validateProcess(): Promise<void> {
    // const taxes = await this.dataServiceFirstOpt.getManyByOptions({
    //   where: {
    //     status: In([STATUS.ACTIVE]),
    //   },
    // });

    // TODO: Save Validation
    // calculateProfitFormula(this.data.formula_string, taxes, 10000, 50, true);
    return;
  }

  async beforeProcess(): Promise<void> {
    return;
  }

  async afterProcess(): Promise<void> {
    const additionalFormula = this.data.additional;
    const taxFormula = this.data.taxes;
    this.dataService.create(null, null, additionalFormula);
    this.dataServiceFirstOpt.create(null, null, taxFormula);
    return;
  }

  get validateRelations(): validateRelations[] {
    return [];
  }

  get uniqueColumns(): columnUniques[] {
    return [];
  }

  get entityTarget(): any {
    return SalesPriceFormulaModel;
  }

  get eventTopics(): EventTopics[] {
    return [
      {
        topic: ProfitShareFormulaUpdatedEvent,
      },
    ];
  }
}
