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 { hashPassword } from 'src/core/helpers/password/bcrypt.helpers';
import { SALT_OR_ROUNDS } from 'src/core/strings/constants/base.constants';

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

  async validateProcess(): Promise<void> {
    Object.assign(this.data, {
      password: await hashPassword(this.data.password, SALT_OR_ROUNDS),
    });
    return;
  }

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

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

  get uniqueColumns(): columnUniques[] {
    return [];
  }

  get entityTarget(): any {
    return UserModel;
  }

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