import { STATUS } from 'src/core/strings/constants/base.constants';
import {
  DATA_FORMAT,
  DATA_TYPE,
  FILTER_FIELD_TYPE,
  FILTER_TYPE,
  REPORT_GROUP,
} from '../../../constant';
import { ReportConfigEntity } from '../../../entities/report-config.entity';
import { RefundType } from 'src/modules/transaction/refund/constants';

export default <ReportConfigEntity>{
  group_name: REPORT_GROUP.transaction_report,
  unique_name: `${REPORT_GROUP.transaction_report}__refunds`,
  label: 'Pengembalian',
  table_schema: `refunds AS main
  LEFT JOIN transactions tr ON tr.id = main.transaction_id`,
  main_table_alias: 'main',
  defaultOrderBy: [],
  lowLevelOrderBy: [],
  filter_period_config: {
    hidden: true,
  },

  column_configs: [
    {
      column: 'main__status',
      query: 'main.status',
      label: 'Status',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.STATUS,
    },
    {
      column: 'main__type',
      query: 'main.type',
      label: 'Tipe Refund',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__code',
      query: 'main.code',
      label: 'Kode',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__request_date',
      query: `to_char(main.request_date, 'DD-MM-YYYY')`,
      label: 'Tgl. Permintaan',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__refund_date',
      query: `to_char(main.refund_date, 'DD-MM-YYYY')`,
      label: 'Tgl. Refund',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'tr__payment_code',
      query: 'tr.payment_code',
      label: 'Kode Settlement',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'tr__settlement_date',
      query: `to_char(tr.settlement_date, 'DD-MM-YYYY')`,
      label: 'Tgl. Settlement',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'tr__payment_total',
      query: 'tr.payment_total',
      label: 'Total Pembayaran',
      type: DATA_TYPE.MEASURE,
      format: DATA_FORMAT.CURRENCY,
    },
    {
      column: 'main__refund_total',
      query: 'main.refund_total',
      label: 'Total Pengembalian',
      type: DATA_TYPE.MEASURE,
      format: DATA_FORMAT.CURRENCY,
    },
    {
      column: 'main__bank_name',
      query: 'main.bank_name',
      label: 'Bank Tujuan',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__bank_account_number',
      query: 'main.bank_account_number',
      label: 'No. Rek. Tujuan',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__bank_account_name',
      query: 'main.bank_account_name',
      label: 'Atas Nama',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'tr__payment_type',
      query: 'tr.payment_type',
      label: 'Tipe Pembayaran',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'tr__customer_name',
      query: 'tr.customer_name',
      label: 'Kontak',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'tr__customer_phone',
      query: 'tr.customer_phone',
      label: 'Telepon',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'tr__customer_description',
      query: 'tr.customer_description',
      label: 'Deskripsi',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__creator_name',
      query: 'main.creator_name',
      label: 'Dibuat Oleh',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__updated_at',
      query: 'main.updated_at',
      label: 'Tgl. Update',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.DATE_EPOCH,
    },
  ],
  filter_configs: [
    {
      filed_label: 'Status',
      filter_column: 'main__status',
      field_type: FILTER_FIELD_TYPE.select,
      filter_type: FILTER_TYPE.TEXT_IN_MEMBER,
      select_custom_options: [
        STATUS.DRAFT,
        STATUS.WAITING,
        STATUS.PENDING,
        STATUS.SETTLED,
        STATUS.REJECTED,
      ],
    },
    {
      filed_label: 'Tipe Refund',
      filter_column: 'main__type',
      field_type: FILTER_FIELD_TYPE.select,
      filter_type: FILTER_TYPE.TEXT_IN_MEMBER,
      select_custom_options: [...Object.values(RefundType)],
    },
    {
      filed_label: 'Kode',
      filter_column: 'main__code',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
    {
      filed_label: 'Tgl. Permintaan',
      filter_column: 'main__request_date',
      field_type: FILTER_FIELD_TYPE.date_range_picker,
      filter_type: FILTER_TYPE.DATE_IN_RANGE_TIMESTAMP,
      date_format: 'DD-MM-YYYY',
    },
    {
      filed_label: 'Tgl. Refund',
      filter_column: 'main__refund_date',
      field_type: FILTER_FIELD_TYPE.date_range_picker,
      filter_type: FILTER_TYPE.DATE_IN_RANGE_TIMESTAMP,
      date_format: 'DD-MM-YYYY',
    },
    {
      filed_label: 'Kode Settlement',
      filter_column: 'tr__payment_code',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
    {
      filed_label: 'Tgl. Settlement',
      filter_column: 'tr__settlement_date',
      field_type: FILTER_FIELD_TYPE.date_range_picker,
      filter_type: FILTER_TYPE.DATE_IN_RANGE_TIMESTAMP,
      date_format: 'DD-MM-YYYY',
    },
    {
      filed_label: 'Bank Tujuan',
      filter_column: 'main__bank_name',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
    {
      filed_label: 'No. Rek. Tujuan',
      filter_column: 'main__bank_account_number',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
    {
      filed_label: 'Atas Nama',
      filter_column: 'main__bank_account_name',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
    {
      filed_label: 'Tipe Pembayaran',
      filter_column: 'tr__payment_type',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
    {
      filed_label: 'Kontak',
      filter_column: 'tr__customer_name',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
    {
      filed_label: 'Telepon',
      filter_column: 'tr__customer_phone',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
    {
      filed_label: 'Dibuat Oleh',
      filter_column: 'main__creator_name',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
    {
      filed_label: 'Tgl. Update',
      filter_column: 'main__updated_at',
      field_type: FILTER_FIELD_TYPE.date_range_picker,
      filter_type: FILTER_TYPE.DATE_IN_RANGE_EPOCH,
    },
  ],
};
