<commit_before>/* eslint-disable max-classes-per-file */
/**
 * mSupply Mobile
 * Sustainable Solutions (NZ) Ltd. 2019
 */

/* eslint-disable quote-props */
/* eslint-disable max-classes-per-file */

import { NAME_TYPE_KEYS } from '../database/utilities/constants';

export const INTERNAL_TO_EXTERNAL = 0;
export const EXTERNAL_TO_INTERNAL = 1;

class SyncTranslator {
  constructor(internalToExternal) {
    this.internalToExternal = internalToExternal;
    this.externalToInternal = {};
    // TODO: replace generators with explicit loops.
    // eslint-disable-next-line no-restricted-syntax
    for (const [key, value] of Object.entries(internalToExternal)) {
      this.externalToInternal[value] = key;
    }
  }

  translate(key, direction) {
    switch (direction) {
      case INTERNAL_TO_EXTERNAL:
      default:
        return this.internalToExternal[key];
      case EXTERNAL_TO_INTERNAL:
        return this.externalToInternal[key];
    }
  }
}

// Map of internal database object types to external record types.
export const RECORD_TYPES = new SyncTranslator({
  IndicatorAttribute: 'indicator_attribute',
  IndicatorValue: 'indicator_value',
  Item: 'item',
  ItemStoreJoin: 'item_store_join',
  ItemBatch: 'item_line',
  ItemDepartment: 'item_department',
  ItemCategory: 'item_category',
  LocalListItem: 'list_local_line',
  MasterList: 'list_master',
  MasterListItem: 'list_master_line',
  MasterListNameJoin: 'list_master_name_join',
  Message: 'message',
  Name: 'name',
  NameStoreJoin: 'name_store_join',
  NumberSequence: 'number',
  NumberToReuse: 'number_reuse',
  Options: 'options',
  PaymentType: 'paymentType',
  Period: 'period',
  PeriodSchedule: 'periodSchedule',
  ProgramIndicator: 'program_indicator',
  Report: 'dashboard_store_report',
  Requisition: 'requisition',
  RequisitionItem: 'requisition_line',
  Stocktake: 'Stock_take',
  StocktakeBatch: 'Stock_take_lines',
  Store: 'store',
  Transaction: 'transact',
  TransactionCategory: 'transaction_category',
  TransactionBatch: 'trans_line',
  User: 'user',
  Unit: 'unit',
  Prescriber: 'clinician',
  ItemDirection: 'item_direction',
  Abbreviation: 'abbreviation',
  InsuranceProvider: 'insuranceProvider',
  InsurancePolicy: 'nameInsuranceJoin',
  Currency: 'currency',
});

export const REQUISITION_TYPES = new SyncTranslator({
  imprest: 'im',
  forecast: 'sh',<commit_msg>Add SyncTranslations for new outgoing tables<commit_after>/* eslint-disable max-classes-per-file */
/**
 * mSupply Mobile
 * Sustainable Solutions (NZ) Ltd. 2019
 */

/* eslint-disable quote-props */
/* eslint-disable max-classes-per-file */

import { NAME_TYPE_KEYS } from '../database/utilities/constants';

export const INTERNAL_TO_EXTERNAL = 0;
export const EXTERNAL_TO_INTERNAL = 1;

class SyncTranslator {
  constructor(internalToExternal) {
    this.internalToExternal = internalToExternal;
    this.externalToInternal = {};
    // TODO: replace generators with explicit loops.
    // eslint-disable-next-line no-restricted-syntax
    for (const [key, value] of Object.entries(internalToExternal)) {
      this.externalToInternal[value] = key;
    }
  }

  translate(key, direction) {
    switch (direction) {
      case INTERNAL_TO_EXTERNAL:
      default:
        return this.internalToExternal[key];
      case EXTERNAL_TO_INTERNAL:
        return this.externalToInternal[key];
    }
  }
}

// Map of internal database object types to external record types.
export const RECORD_TYPES = new SyncTranslator({
  IndicatorAttribute: 'indicator_attribute',
  IndicatorValue: 'indicator_value',
  Item: 'item',
  ItemStoreJoin: 'item_store_join',
  ItemBatch: 'item_line',
  ItemDepartment: 'item_department',
  ItemCategory: 'item_category',
  LocalListItem: 'list_local_line',
  MasterList: 'list_master',
  MasterListItem: 'list_master_line',
  MasterListNameJoin: 'list_master_name_join',
  Message: 'message',
  Name: 'name',
  NameStoreJoin: 'name_store_join',
  NumberSequence: 'number',
  NumberToReuse: 'number_reuse',
  Options: 'options',
  PaymentType: 'paymentType',
  Period: 'period',
  PeriodSchedule: 'periodSchedule',
  ProgramIndicator: 'program_indicator',
  Report: 'dashboard_store_report',
  Requisition: 'requisition',
  RequisitionItem: 'requisition_line',
  Stocktake: 'Stock_take',
  StocktakeBatch: 'Stock_take_lines',
  Store: 'store',
  Transaction: 'transact',
  TransactionCategory: 'transaction_category',
  TransactionBatch: 'trans_line',
  User: 'user',
  Unit: 'unit',
  Prescriber: 'clinician',
  ItemDirection: 'item_direction',
  Abbreviation: 'abbreviation',
  InsuranceProvider: 'insuranceProvider',
  InsurancePolicy: 'nameInsuranceJoin',
  Currency: 'currency',
  LocationMovement: 'location_movement',
  VaccineVialMonitorStatusLog: 'vaccine_vial_monitor_status_log',
  Sensor: 'sensor',
  Location: 'Location',
  TemperatureLog: 'temperature_log',
  TemperatureBreach: 'temperature_breach',
  SensorLog: 'sensorLog',
});

export const REQUISITION_TYPES = new SyncTranslator({
  imprest: 'im',
  forecast: 'sh',
{'fraction_non_alphanumeric': 0.1172962226640159, 'fraction_numerical': 0.002385685884691849, 'mean_word_length': 4.946808510638298, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6059725', 'n_tokens_mistral': 1641, 'n_tokens_neox': 1598, 'n_words': 340}