import { Injectable } from '@nestjs/common';
import { BaseUpdateManager } from 'src/core/modules/domain/usecase/managers/base-update.manager';
import {
  EventTopics,
  columnUniques,
  validateRelations,
} from 'src/core/strings/constants/interface.constants';
import { TenantUpdatedEvent } from '../../entities/event/tenant-updated.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 { UserRole } from 'src/modules/user-related/user/constants';

@Injectable()
export class UpdateTenantManager extends BaseUpdateManager<UserEntity> {
  get validateRelations(): validateRelations[] {
    return [];
  }

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

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

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

  get uniqueColumns(): columnUniques[] {
    return [
      // validate username (all data)
      { column: 'username' },

      // validate name (hanya data dengan role tenant)
      {
        column: 'name',
        query: {
          role: UserRole.TENANT,
        },
      },
    ];
  }

  get entityTarget(): any {
    return UserModel;
  }

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