import { Injectable } from '@nestjs/common';
import { BaseDetailManager } from 'src/core/modules/domain/usecase/managers/base-detail.manager';
import { TransactionEntity } from '../../entities/transaction.entity';
import { RelationParam } from 'src/core/modules/domain/entities/base-filter.entity';
import { mappingTransaction } from './helpers/mapping-transaction.helper';

@Injectable()
export class DetailTransactionManager extends BaseDetailManager<TransactionEntity> {
  async prepareData(): Promise<void> {
    return;
  }

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

  async afterProcess(): Promise<void> {
    mappingTransaction(this.result);
    return;
  }

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

      // relation join and select (relasi yang ingin ditampilkan),
      selectRelations: [
        'items',
        'items.bundling_items',
        'items.refunds item_refunds',
        'item_refunds.refund item_refunds_refund',
        'refunds',

        'items.item items_item',
        'items_item.time_group items_item_time_group',
      ],

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

  get selects(): string[] {
    return [
      `${this.tableName}.id`,
      `${this.tableName}.creator_counter_no`,
      `${this.tableName}.creator_counter_name`,
      `${this.tableName}.creator_name`,
      `${this.tableName}.created_at`,
      `${this.tableName}.updated_at`,
      `${this.tableName}.editor_name`,
      `${this.tableName}.invoice_code`,
      `${this.tableName}.invoice_date`,
      `${this.tableName}.settlement_date`,

      `${this.tableName}.season_period_id`,
      `${this.tableName}.season_period_name`,
      `${this.tableName}.season_period_type_id`,
      `${this.tableName}.season_period_type_name`,

      `${this.tableName}.status`,
      `${this.tableName}.no_of_group`,
      `${this.tableName}.customer_type`,
      `${this.tableName}.customer_name`,
      `${this.tableName}.customer_phone`,
      `${this.tableName}.customer_email`,
      `${this.tableName}.customer_description`,
      `${this.tableName}.booking_date`,

      `${this.tableName}.discount_percentage`,
      `${this.tableName}.discount_value`,

      `${this.tableName}.payment_type`,
      `${this.tableName}.payment_type_counter`,
      `${this.tableName}.payment_date`,
      `${this.tableName}.payment_total_pay`,
      `${this.tableName}.payment_type_method_id`,
      `${this.tableName}.payment_type_method_name`,
      `${this.tableName}.payment_type_method_number`,
      `${this.tableName}.payment_card_information`,
      `${this.tableName}.payment_code_reference`,
      `${this.tableName}.payment_code`,

      `${this.tableName}.payment_sub_total`,
      `${this.tableName}.payment_discount_total`,
      `${this.tableName}.payment_total`,

      `${this.tableName}.payment_midtrans_url`,

      'items',
      'bundling_items',
      'item_refunds',
      'item_refunds_refund.id',
      'item_refunds_refund.status',

      'refunds',
      'items_item',
      'items_item_time_group',
    ];
  }

  get setFindProperties(): any {
    return {
      id: this.dataId,
    };
  }
}
