import { BaseBatchDeleteManager } from 'src/core/modules/domain/usecase/managers/base-batch-delete.manager';
import {
  EventTopics,
  validateRelations,
} from 'src/core/strings/constants/interface.constants';
import { TenantDeletedEvent } from '../../entities/event/tenant-deleted.event';
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
import { Injectable } from '@nestjs/common';
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
import { SelectQueryBuilder } from 'typeorm';
import { STATUS } from 'src/core/strings/constants/base.constants';

@Injectable()
export class BatchDeleteTenantManager extends BaseBatchDeleteManager<UserEntity> {
  get validateRelations(): validateRelations[] {
    return [
      {
        relation: 'items',
        query: (qb: SelectQueryBuilder<any>) => {
          return qb.andWhere('total_items.status In (:...statuses)', {
            statuses: [STATUS.ACTIVE],
          });
        },
        message: 'Gagal! terdapat item yang aktif',
      },
    ];
  }

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

  async validateData(data: UserEntity): Promise<void> {
    return;
  }

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

  get entityTarget(): any {
    return UserModel;
  }

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

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