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

export default <ReportConfigEntity>{
  group_name: REPORT_GROUP.transaction_report,
  unique_name: `${REPORT_GROUP.transaction_report}__tax`,
  label: 'Tax Pendapatan',
  table_schema: `transactions main
  left join transaction_taxes tr_taxes on tr_taxes.transaction_id = main.id`,
  main_table_alias: 'main',
  whereDefaultConditions: [
    {
      column: 'main.status',
      filter_type: FILTER_TYPE.TEXT_IN_MEMBER,
      values: [STATUS.SETTLED, STATUS.REFUNDED, STATUS.PROCESS_REFUND],
    },
    {
      column: 'main.is_recap_transaction',
      filter_type: FILTER_TYPE.TEXT_EQUAL,
      values: [false],
    },
  ],
  defaultOrderBy: [],
  lowLevelOrderBy: [],
  filter_period_config: {
    hidden: true,
  },

  column_configs: [
    {
      column: 'main__payment_date',
      query: `to_char(main.payment_date, 'DD-MM-YYYY')`,
      label: 'Tgl. Transaksi',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__status',
      query: 'main.status',
      label: 'Status',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.STATUS,
    },
    {
      column: 'main__type',
      query: 'main.type',
      label: 'Sumber',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__invoice_code',
      query: `CASE WHEN main.type != 'counter' THEN main.invoice_code ELSE null END`,
      label: 'Kode Booking',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__payment_code',
      query: `CASE WHEN main.type = 'counter' THEN main.invoice_code ELSE main.payment_code END`,
      label: 'Kode Pembayaran',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__payment_total',
      query: 'main.payment_total',
      label: 'Total Penjualan',
      type: DATA_TYPE.MEASURE,
      format: DATA_FORMAT.CURRENCY,
    },
    {
      column: 'main__payment_total_dpp',
      query: 'main.payment_total_dpp',
      label: 'DPP',
      type: DATA_TYPE.MEASURE,
      format: DATA_FORMAT.CURRENCY,
    },
    {
      column: 'tr_taxes__tax_name',
      query: 'tr_taxes.tax_name',
      label: 'Tipe Tax',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'tr_taxes__tax_total_value',
      query: 'tr_taxes.tax_total_value',
      label: 'Value Tax',
      type: DATA_TYPE.MEASURE,
      format: DATA_FORMAT.CURRENCY,
    },
  ],
  filter_configs: [
    {
      filed_label: 'Tgl. Transaksi',
      filter_column: 'main__payment_date',
      field_type: FILTER_FIELD_TYPE.date_range_picker,
      filter_type: FILTER_TYPE.DATE_IN_RANGE_TIMESTAMP,
      // date_format: 'DD-MM-YYYY',
      date_format: 'YYYY-MM-DD',
    },
    {
      filed_label: 'Sumber',
      filter_column: 'main__type',
      field_type: FILTER_FIELD_TYPE.select,
      filter_type: FILTER_TYPE.TEXT_IN_MEMBER,
      select_custom_options: [...Object.values(TransactionType)],
    },
    {
      filed_label: 'Kode Booking',
      filter_column: 'main__invoice_code',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
    {
      filed_label: 'Kode Pembayaran',
      filter_column: 'main__payment_code',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
    {
      filed_label: 'Tipe Tax',
      filter_column: 'tr_taxes__tax_name',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
  ],
  customQueryColumn(column) {
    if (column === 'main__payment_date') return 'main.payment_date';
    return;
  },
};
