import { BaseBatchDeleteManager } from 'src/core/modules/domain/usecase/managers/base-batch-delete.manager';
import { ItemEntity } from '../../entities/item.entity';
import {
  EventTopics,
  validateRelations,
} from 'src/core/strings/constants/interface.constants';
import { ItemModel } from '../../../data/models/item.model';
import { ItemDeletedEvent } from '../../entities/event/item-deleted.event';
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
import { Injectable } from '@nestjs/common';
import { validateRelation } from './helpers/validasi-relation.helper';

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

  async validateData(data: ItemEntity): Promise<void> {
    await validateRelation(this.dataService, data.id);
    return;
  }

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

  get validateRelations(): validateRelations[] {
    return [
      {
        relation: 'bundling_parents',
        message: `Gagal! Item sudah berelasi dengen bundling`,
      },
    ];
  }

  get entityTarget(): any {
    return ItemModel;
  }

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

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