import {
  DATA_FORMAT,
  DATA_TYPE,
  FILTER_FIELD_TYPE,
  FILTER_TYPE,
  REPORT_GROUP,
} from '../../../constant';
import { ReportConfigEntity } from '../../../entities/report-config.entity';

export default <ReportConfigEntity>{
  group_name: REPORT_GROUP.transaction_report,
  unique_name: `${REPORT_GROUP.transaction_report}__vid_code`,
  label: 'Kode VIP',
  table_schema: `vip_codes main
  LEFT JOIN (
      select
          tr.discount_code_id AS vip_code_id,
          COUNT(tr.discount_code_id) AS total_transaction
      from transactions tr
      where  tr.discount_code_id is not null
      group by tr.discount_code_id
  ) voucher_used ON voucher_used.vip_code_id::uuid = main.id`,
  main_table_alias: 'main',
  whereDefaultConditions: [],
  defaultOrderBy: [],
  lowLevelOrderBy: [`main.created_at DESC`],
  filter_period_config: {
    hidden: true,
  },
  column_configs: [
    {
      column: 'main__code',
      query: 'main.code',
      label: 'Kode Voucher',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__otp_code',
      query: 'main.otp_code',
      label: 'Kode OTP',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__discount',
      query: 'CASE WHEN main.discount > 0 THEN main.discount ELSE null END',
      label: 'Diskon (%)',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__discount_value',
      query:
        'CASE WHEN main.discount_value > 0 THEN main.discount_value ELSE null END',
      label: 'Diskon (Rp)',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.CURRENCY,
    },
    {
      column: 'voucher_used__total_transaction',
      query: 'voucher_used.total_transaction',
      label: 'Jumlah Transaksi',
      type: DATA_TYPE.MEASURE,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__created_at',
      query: `to_char(cast(to_timestamp(main.created_at/1000) as date),'DD-MM-YYYY')`,
      label: 'Tgl. Dibuat',
      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,
    },
  ],
  filter_configs: [
    {
      filed_label: 'Kode Voucher',
      filter_column: 'main__code',
      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. Dibuat',
      filter_column: 'main__date',
      field_type: FILTER_FIELD_TYPE.date_range_picker,
      filter_type: FILTER_TYPE.DATE_IN_RANGE_TIMESTAMP,
      date_format: 'DD-MM-YYYY',
    },
  ],
};
