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

@Injectable()
export class DeleteTenantManager extends BaseDeleteManager<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',
      },
    ];
  }

  getResult(): string {
    return `Success`;
  }

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

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

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

  get entityTarget(): any {
    return UserModel;
  }

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