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}__demography`,
  label: 'Demography',
  table_schema: `transactions main
  left join transaction_demographies demography on  demography.transaction_id::uuid = main.id`,
  main_table_alias: 'main',
  whereDefaultConditions: [
    {
      column: 'main.status',
      filter_type: FILTER_TYPE.TEXT_IN_MEMBER,
      values: [STATUS.SETTLED],
    },
    {
      column: 'main.is_recap_transaction',
      filter_type: FILTER_TYPE.TEXT_EQUAL,
      values: [false],
    },
    {
      column: 'main.type',
      filter_type: FILTER_TYPE.TEXT_EQUAL,
      values: ['counter'],
    },
  ],
  defaultOrderBy: [],
  lowLevelOrderBy: [],
  filter_period_config: {
    hidden: true,
  },

  column_configs: [
    {
      column: 'main__date',
      query: `CASE WHEN main.type ='counter' THEN to_char(main.payment_date, 'DD-MM-YYYY') ELSE to_char(main.booking_date, 'DD-MM-YYYY') END`,
      label: 'Tanggal',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__type',
      query: 'main.type',
      label: 'Sumber',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__creator_counter_no',
      query: 'main.creator_counter_no',
      label: 'No.PoS',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__creator_counter_name',
      query: 'main.creator_counter_name',
      label: 'Nama PoS',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__creator_name',
      query: 'main.creator_name',
      label: 'Nama Kasir',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__code',
      query: `CASE WHEN main.invoice_code is not null THEN main.invoice_code ELSE main.payment_code END`,
      label: 'Kode',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'demography__woman',
      query: `demography.woman`,
      label: 'Wanita',
      type: DATA_TYPE.MEASURE,
      format: DATA_FORMAT.NUMBER,
    },
    {
      column: 'demography__man',
      query: `demography.man`,
      label: 'Pria',
      type: DATA_TYPE.MEASURE,
      format: DATA_FORMAT.NUMBER,
    },
    {
      column: 'demography__teen',
      query: `demography.teen`,
      label: 'Remaja',
      type: DATA_TYPE.MEASURE,
      format: DATA_FORMAT.NUMBER,
    },
    {
      column: 'demography__child',
      query: `demography.child`,
      label: 'Anak-anak',
      type: DATA_TYPE.MEASURE,
      format: DATA_FORMAT.NUMBER,
    },
  ],
  filter_configs: [
    {
      filed_label: 'Tanggal',
      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',
    },

    {
      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',
      filter_column: 'main__code',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
  ],
};
