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

export default <ReportConfigEntity>{
  group_name: REPORT_GROUP.transaction_report,
  unique_name: `${REPORT_GROUP.transaction_report}__booking`,
  label: 'Pemesanan',
  table_schema: `transactions AS main
  LEFT JOIN refunds refund ON refund.transaction_id = main.id`,
  main_table_alias: 'main',
  whereDefaultConditions: [
    {
      column: 'main.type',
      filter_type: FILTER_TYPE.TEXT_IN_MEMBER,
      values: [TransactionType.ADMIN, TransactionType.ONLINE],
    },
  ],
  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__booking_date',
      query: `to_char(main.booking_date, 'DD-MM-YYYY')`,
      label: 'Tgl. Booking',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__no_of_group',
      query: 'main.no_of_group::NUMERIC',
      label: '#Visitor',
      type: DATA_TYPE.MEASURE,
      format: DATA_FORMAT.NUMBER,
    },
    {
      column: 'main__type',
      query: 'main.type',
      label: 'Sumber',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__payment_total',
      query: 'main.payment_total',
      label: 'Total Invoice',
      type: DATA_TYPE.MEASURE,
      format: DATA_FORMAT.CURRENCY,
    },
    {
      column: 'main__customer_type',
      query: 'main.customer_type',
      label: 'Tipe',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__customer_name',
      query: 'main.customer_name',
      label: 'Kontak',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__customer_phone',
      query: 'main.customer_phone',
      label: 'Telepon',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__customer_description',
      query: 'main.customer_description',
      label: 'Deskripsi',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__payment_type',
      query: 'main.payment_type',
      label: 'Tipe Pembayaran',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__payment_type_method_name',
      query: 'main.payment_type_method_name',
      label: 'Bank',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },

    {
      column: 'main__invoice_date',
      query: `to_char(main.invoice_date, 'DD-MM-YYYY')`,
      label: 'Tgl. Invoice',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__invoice_code',
      query: 'main.invoice_code',
      label: 'Kode Invoice',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__settlement_date',
      query: `to_char(main.settlement_date, 'DD-MM-YYYY')`,
      label: 'Tgl Settlement',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'refund__request_date',
      query: `to_char(refund.request_date, 'DD-MM-YYYY')`,
      label: 'Request Refund',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'refund__code',
      query: 'refund.code',
      label: 'Kode Refund',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'refund__refund_date',
      query: `to_char(refund.refund_date, 'DD-MM-YYYY')`,
      label: 'Tgl. Refund',
      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: 'Tgl. Booking',
      filter_column: 'main__booking_date',
      field_type: FILTER_FIELD_TYPE.date_range_picker,
      filter_type: FILTER_TYPE.DATE_IN_RANGE_TIMESTAMP,
      date_format: 'DD-MM-YYYY',
    },
    {
      filed_label: 'Sumber',
      filter_column: 'main__type',
      field_type: FILTER_FIELD_TYPE.select,
      filter_type: FILTER_TYPE.TEXT_IN_MEMBER,
      select_custom_options: [
        TransactionType.ADMIN,
        TransactionType.COUNTER,
        TransactionType.ONLINE,
      ],
    },
    {
      filed_label: 'Tipe',
      filter_column: 'main__customer_type',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
    {
      filed_label: 'Kontak',
      filter_column: 'main__customer_name',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
    {
      filed_label: 'Tipe Pembayaran',
      filter_column: 'main__payment_type',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
    {
      filed_label: 'Bank',
      filter_column: 'main__payment_type_method_name',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
    {
      filed_label: 'Tgl. Invoice',
      filter_column: 'main__invoice_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 Invoice',
      filter_column: 'main__invoice_code',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
    {
      filed_label: 'Tgl. Settlement',
      filter_column: 'main__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: 'Request Refund',
      filter_column: 'refund__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: 'Kode Refund',
      filter_column: 'refund__code',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
    {
      filed_label: 'Tgl. Refund',
      filter_column: 'refund__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: '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,
    },
  ],
};
