import { BaseBatchDeleteManager } from 'src/core/modules/domain/usecase/managers/base-batch-delete.manager';
import { TransactionEntity } from '../../entities/transaction.entity';
import {
  EventTopics,
  validateRelations,
} from 'src/core/strings/constants/interface.constants';
import { TransactionModel } from '../../../data/models/transaction.model';
import { TransactionDeletedEvent } from '../../entities/event/transaction-deleted.event';
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
import {
  HttpStatus,
  Injectable,
  UnprocessableEntityException,
} from '@nestjs/common';
import { STATUS } from 'src/core/strings/constants/base.constants';

@Injectable()
export class BatchDeleteTransactionManager extends BaseBatchDeleteManager<TransactionEntity> {
  async beforeProcess(): Promise<void> {
    return;
  }

  async validateData(data: TransactionEntity): Promise<void> {
    const allowDelete = [
      STATUS.DRAFT,
      STATUS.ACTIVE,
      STATUS.CANCEL,
      STATUS.PENDING,
      STATUS.EXPIRED,
    ].includes(data.status);

    if (!allowDelete) {
      throw new UnprocessableEntityException({
        statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
        message: `Gagal! data dengan status ${data.status} tidak bisa di hapus!`,
        error: 'Unprocessable Entity',
      });
    }
    return;
  }

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

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

  get entityTarget(): any {
    return TransactionModel;
  }

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

  getResult(): BatchResult {
    return this.result;
  }
}
