import {
  HttpStatus,
  Injectable,
  UnprocessableEntityException,
} from '@nestjs/common';
import { BaseDeleteManager } from 'src/core/modules/domain/usecase/managers/base-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';

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

  async validateProcess(): Promise<void> {
    const relationData = await this.dataServiceFirstOpt.getOneByOptions({
      where: {
        season_type_id: this.dataId,
      },
    });

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

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

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

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

  get entityTarget(): any {
    return SeasonTypeModel;
  }

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