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

@Injectable()
export class IndexFaqManager extends BaseIndexManager<FaqEntity> {
  async prepareData(): Promise<void> {
    this.filterParam.order_by = `${this.tableName}.sort_order`;
    this.filterParam.order_type = ORDER_TYPE.ASC;
    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}.status`,
      `${this.tableName}.sort_order`,
      `${this.tableName}.created_at`,
      `${this.tableName}.creator_name`,
      `${this.tableName}.updated_at`,
      `${this.tableName}.editor_name`,
      `${this.tableName}.title`,
      `${this.tableName}.description`,
    ];
  }

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

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