import { Injectable } from '@nestjs/common';
import { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager';
import {
  EventTopics,
  validateRelations,
} from 'src/core/strings/constants/interface.constants';
import { TenantChangeStatusEvent } from '../../entities/event/tenant-change-status.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 InactiveTenantManager extends BaseUpdateStatusManager<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 inactive data ${this.result.name}`;
  }

  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: TenantChangeStatusEvent,
        data: this.data,
      },
    ];
  }
}
