import { Injectable } from '@nestjs/common';
import {
  EventTopics,
  columnUniques,
  validateRelations,
} from 'src/core/strings/constants/interface.constants';
import { BaseCreateManager } from 'src/core/modules/domain/usecase/managers/base-create.manager';
import { STATUS } from 'src/core/strings/constants/base.constants';
import { QueueModel } from '../../data/models/queue.model';
import { generateRandom } from 'src/modules/transaction/vip-code/domain/usecases/managers/helpers/generate-random.helper';
import { QueueBucketReadService } from '../../data/services/queue-bucket';

@Injectable()
export class RegisterQueueManager extends BaseCreateManager<QueueModel> {
  constructor(private readonly queueService: QueueBucketReadService) {
    super();
  }

  async averageTime(): Promise<number> {
    const item = await this.getItem();
    return item.item.item.play_estimation;
  }

  async beforeProcess(): Promise<void> {
    Object.assign(this.data, {
      status: STATUS.WAITING,
      time: new Date().getTime(),
      vip: false,
      code: `A${generateRandom(4, true)}`,
    });
    return;
  }

  async getItem(): Promise<QueueModel> {
    return this.dataService.repo.findOne({
      relations: ['item', 'item.item'],
      where: {
        item_id: this.data.item_id,
      },
    });
  }

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

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

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

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

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