import { Injectable } from '@nestjs/common';
import { BaseDeleteManager } from 'src/core/modules/domain/usecase/managers/base-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 { validateRelation } from './helpers/validasi-relation.helper';

@Injectable()
export class DeleteItemManager extends BaseDeleteManager<ItemEntity> {
  getResult(): string {
    return `Success`;
  }

  async validateProcess(): Promise<void> {
    await validateRelation(this.dataService, this.dataId);
    return;
  }

  async beforeProcess(): Promise<void> {
    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,
        data: this.data,
      },
    ];
  }
}
