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

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

  async validateData(data: SeasonTypeEntity): Promise<void> {
    const relationData = await this.dataServiceFirstOpt.getOneByOptions({
      where: {
        season_type_id: data.id,
      },
    });

    if (relationData) {
      throw new UnprocessableEntityException({
        statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
        message: `Gagagl! data sudah berelasi dengen season period.`,
        error: 'Unprocessable Entity',
      });
    }
    return;
  }

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

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

  get entityTarget(): any {
    return SeasonTypeModel;
  }

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

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