import {
  HttpStatus,
  Injectable,
  UnprocessableEntityException,
} from '@nestjs/common';
import { BaseUpdateManager } from 'src/core/modules/domain/usecase/managers/base-update.manager';
import { RefundEntity } from '../../entities/refund.entity';
import { RefundModel } from '../../../data/models/refund.model';
import { RefundUpdatedEvent } from '../../entities/event/refund-updated.event';
import {
  EventTopics,
  columnUniques,
  validateRelations,
} from 'src/core/strings/constants/interface.constants';

@Injectable()
export class UpdateRefundManager extends BaseUpdateManager<RefundEntity> {
  async validateProcess(): Promise<void> {
    return;
  }

  async beforeProcess(): Promise<void> {
    const refund_items = this.data.refund_items?.map((item) => {
      return {
        transaction_item: item,
        qty_refund: item.qty_refund,
        refund_total: item.refund_total,
        refund_sub_total: item.refund_sub_total,
      };
    });

    Object.assign(this.data, {
      refund_items: refund_items ?? [],
    });
    return;
  }

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

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

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

  get entityTarget(): any {
    return RefundModel;
  }

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