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

@Injectable()
export class IndexPaymentMethodManager extends BaseIndexManager<PaymentMethodEntity> {
  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}.status`,
      `${this.tableName}.type`,
      `${this.tableName}.issuer_name`,
      `${this.tableName}.account_number`,
      `${this.tableName}.account_name`,
      `${this.tableName}.qr_image`,
      `${this.tableName}.note`,
      `${this.tableName}.created_at`,
      `${this.tableName}.updated_at`,
      `${this.tableName}.creator_name`,
      `${this.tableName}.editor_name`,
    ];
  }

  get specificFilter(): Param[] {
    return [
      {
        cols: `${this.tableName}.issuer_name`,
        data: this.filterParam.names,
      },
      {
        cols: `${this.tableName}.issuer_name`,
        data: this.filterParam.issuers,
      },
      {
        cols: `${this.tableName}.type::text`,
        data: this.filterParam.types,
      },
      {
        cols: `${this.tableName}.account_number`,
        data: this.filterParam.account_numbers,
      },
      {
        cols: `${this.tableName}.account_name`,
        data: this.filterParam.account_names,
      },
      {
        cols: `${this.tableName}.note`,
        data: this.filterParam.notes,
      },
    ];
  }

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