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

@Injectable()
export class IndexGateManager extends BaseIndexManager<GateEntity> {
  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: ['item'],

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

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

      'item.id',
      'item.name',
      'item.status',
      'item.item_type',
      'item.base_price',
      'item.hpp',
    ];
  }

  get specificFilter(): Param[] {
    return [
      {
        cols: `${this.tableName}.code`,
        data: this.filterParam.codes,
      },
      {
        cols: `${this.tableName}.type`,
        data: this.filterParam.types,
      },
      {
        cols: `${this.tableName}.note`,
        data: this.filterParam.notes,
      },
      {
        cols: `item.name`,
        data: this.filterParam.item_names,
      },
    ];
  }

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