import { Injectable } from '@nestjs/common';
import {
  EventTopics,
  columnUniques,
  validateRelations,
} from 'src/core/strings/constants/interface.constants';
import { UserEntity } from '../../entities/user.entity';
import { UserModel } from '../../../data/models/user.model';
import { BaseCreateManager } from 'src/core/modules/domain/usecase/managers/base-create.manager';
import { UserCreatedEvent } from '../../entities/event/user-created.event';
import { UserRole } from '../../../constants';
import { hashPassword } from 'src/core/helpers/password/bcrypt.helpers';
import { SALT_OR_ROUNDS } from 'src/core/strings/constants/base.constants';

@Injectable()
export class CreateUserManager extends BaseCreateManager<UserEntity> {
  async beforeProcess(): Promise<void> {
    Object.assign(this.data, {
      password: await hashPassword(this.data.password, SALT_OR_ROUNDS),
    });

    return;
  }

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

  async generateConfig(): Promise<void> {
    // TODO: Implement logic here
  }

  get validateRelations(): validateRelations[] {
    return [];
  }

  get uniqueColumns(): columnUniques[] {
    return [
      {
        column: 'username',
      },
    ];
  }

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

  get entityTarget(): any {
    return UserModel;
  }
}
