import { Injectable } from '@nestjs/common';
import { BaseIndexManager } from 'src/core/modules/domain/usecase/managers/base-index.manager';
import { ItemEntity } from '../../entities/item.entity';
import { SelectQueryBuilder } from 'typeorm';
import {
  Param,
  RelationParam,
} from 'src/core/modules/domain/entities/base-filter.entity';
import { STATUS } from 'src/core/strings/constants/base.constants';

@Injectable()
export class IndexItemQueueManager extends BaseIndexManager<ItemEntity> {
  async prepareData(): Promise<void> {
    return;
  }

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

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

  get relations(): RelationParam {
    return {
      // relation only join (for query purpose)
      joinRelations: [],

      // relation join and select (relasi yang ingin ditampilkan),
      selectRelations: [],

      // relation yang hanya ingin dihitung (akan return number)
      countRelations: [],
    };
  }

  get selects(): string[] {
    return [
      `${this.tableName}.id`,
      `${this.tableName}.created_at`,
      `${this.tableName}.name`,
    ];
  }

  get specificFilter(): Param[] {
    return [
      {
        cols: `${this.tableName}.name`,
        data: this.filterParam.names,
      },
    ];
  }

  setQueryFilter(
    queryBuilder: SelectQueryBuilder<ItemEntity>,
  ): SelectQueryBuilder<ItemEntity> {
    queryBuilder.andWhere(`${this.tableName}.status = :status`, {
      status: STATUS.ACTIVE,
    });

    queryBuilder.andWhere(`${this.tableName}.use_queue = :queue`, {
      queue: true,
    });

    return queryBuilder;
  }
}
