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

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

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

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

  get relations(): RelationParam {
    return {
      joinRelations: [],
      selectRelations: ['items'],
      countRelations: [],
    };
  }

  get selects(): string[] {
    return [
      `${this.tableName}.id`,
      `${this.tableName}.status`,
      `${this.tableName}.name`,
      `${this.tableName}.item_type`,
      `${this.tableName}.created_at`,
      `${this.tableName}.creator_name`,
      `${this.tableName}.updated_at`,
      `${this.tableName}.editor_name`,

      `items.id`,
      `items.created_at`,
      `items.status`,
      `items.item_type`,
      `items.name`,
      `items.hpp`,
      `items.limit_type`,
      `items.limit_value`,
      `items.base_price`,
      `items.share_profit`,
      `items.play_estimation`,
    ];
  }

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

  setQueryFilter(
    queryBuilder: SelectQueryBuilder<ItemQueueEntity>,
  ): SelectQueryBuilder<ItemQueueEntity> {
    return queryBuilder;
  }
}
