import { Injectable } from '@nestjs/common';
import {
  EventTopics,
  columnUniques,
  validateRelations,
} from 'src/core/strings/constants/interface.constants';
import { TransactionEntity } from '../../entities/transaction.entity';
import { TransactionModel } from '../../../data/models/transaction.model';
import { BaseCreateManager } from 'src/core/modules/domain/usecase/managers/base-create.manager';
import { TransactionCreatedEvent } from '../../entities/event/transaction-created.event';
import { TransactionType } from '../../../constants';
import { mappingRevertTransaction } from './helpers/mapping-transaction.helper';

@Injectable()
export class CreateTransactionManager extends BaseCreateManager<TransactionEntity> {
  async beforeProcess(): Promise<void> {
    mappingRevertTransaction(this.data, TransactionType.ADMIN);
    return;
  }

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

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

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

  get eventTopics(): EventTopics[] {
    return [
      {
        topic: TransactionCreatedEvent,
        data: this.data,
      },
    ];
  }

  get entityTarget(): any {
    return TransactionModel;
  }
}
