import { PosLogType } from 'src/modules/configuration/log/domain/entities/pos-log.entity';
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}__cash_withdrawals`,
  label: 'Penarikan Kas',
  table_schema: 'logs_pos main',
  main_table_alias: 'main',
  defaultOrderBy: [],
  lowLevelOrderBy: [],
  filter_period_config: {
    hidden: true,
  },
  whereDefaultConditions: [
    {
      column: 'main.type',
      filter_type: FILTER_TYPE.TEXT_IN_MEMBER,
      values: [PosLogType.cash_witdrawal],
    },
  ],
  whereCondition(filterModel) {
    return [`main.created_at is not null`];
  },
  column_configs: [
    {
      column: 'main__date',
      query: `to_char(cast(to_timestamp(main.created_at/1000) as date),'DD-MM-YYYY')`,
      label: 'Tanggal',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__time',
      query: 'main.created_at',
      label: 'Jam',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.DATE_EPOCH,
      date_format: 'HH:mm',
    },
    {
      column: 'main__drawn_by_name',
      query: 'main.drawn_by_name',
      label: 'Nama Penarik',
      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__pos_number',
      query: 'main.pos_number',
      label: 'No. PoS',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__pos_name',
      query: 'main.pos_name',
      label: 'Nama PoS',
      type: DATA_TYPE.DIMENSION,
      format: DATA_FORMAT.TEXT,
    },
    {
      column: 'main__total_balance',
      query: 'main.total_balance',
      label: 'Total Penarikan',
      type: DATA_TYPE.MEASURE,
      format: DATA_FORMAT.CURRENCY,
    },
  ],
  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: 'Nama Penarik',
      filter_column: 'main__drawn_by_name',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
    {
      filed_label: 'Nama Kasir',
      filter_column: 'main__creator_name',
      field_type: FILTER_FIELD_TYPE.input_tag,
      filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
    },
    {
      filed_label: 'No. PoS',
      filter_column: 'main__pos_number',
      field_type: FILTER_FIELD_TYPE.input_number,
      filter_type: FILTER_TYPE.NUMBER_EQUAL,
    },
  ],
};
