import { BaseBatchUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-batch-update-status.manager';
import { RefundEntity } from '../../entities/refund.entity';
import {
  EventTopics,
  validateRelations,
} from 'src/core/strings/constants/interface.constants';
import { RefundModel } from '../../../data/models/refund.model';
import { RefundChangeStatusEvent } from '../../entities/event/refund-change-status.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 BatchCancelRefundManager extends BaseBatchUpdateStatusManager<RefundEntity> {
  validateData(data: RefundEntity): Promise<void> {
    if (
      ![
        STATUS.REFUNDED,
        STATUS.PENDING,
        STATUS.PROCESS_REFUND,
        STATUS.PARTIAL_REFUND,
      ].includes(data.status)
    ) {
      throw new UnprocessableEntityException({
        statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
        message: `Gagal! hanya data dengan status ${STATUS.REFUNDED}, ${STATUS.PROCESS_REFUND} , ${STATUS.PARTIAL_REFUND} dan ${STATUS.PENDING} yang dapat dicancel`,
        error: 'Unprocessable Entity',
      });
    }
    return;
  }

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

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

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

  get entityTarget(): any {
    return RefundModel;
  }

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

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