# frozen_string_literal: true module ErpTools module Id DELIMITER = '-' ADDRESS_PREFIX = 'CI-ADDR' CUSTOMER_DEPOSIT_PREFIX = 'CI-CD' CUSTOMER_PREFIX = 'CI-CUS' INVENTORY_RECEIPT_PREFIX = 'CI-IR' ITEM_FULFILLMENT_PREFIX = 'CI-IF' JOB_PREFIX = 'CI-JOB' MMS_FINISHED_GOOD_SUFFIX = 'F' MMS_SKU_PREFIX = 'INVITM-MMS' PURCHASE_ORDER_PREFIX = 'CI-PO' SALES_ORDER_PREFIX = 'CI-SO' WORK_ORDER_PREFIX = 'CI-WO' class InvalidIdentifier < ::ErpTools::Error; end class << self def address(address_composite_id) raise_if_empty!(address_composite_id) [ADDRESS_PREFIX, address_composite_id.to_s].join(DELIMITER) end def customer_deposit(payment_id) raise_if_empty!(payment_id) [CUSTOMER_DEPOSIT_PREFIX, payment_id.to_s].join(DELIMITER) end def customer(account_id) raise_if_empty!(account_id) [CUSTOMER_PREFIX, account_id.to_s].join(DELIMITER) end def inventory_receipt(inventory_receipt_id) raise_if_empty!(inventory_receipt_id) [INVENTORY_RECEIPT_PREFIX, inventory_receipt_id.to_s].join(DELIMITER) end def item_fulfillment(item_fulfillment_id) raise_if_empty!(item_fulfillment_id) [ITEM_FULFILLMENT_PREFIX, item_fulfillment_id.to_s].join(DELIMITER) end def job_order(ci_order_id) raise_if_empty!(ci_order_id) [JOB_PREFIX, ci_order_id.to_s].join(DELIMITER) end def blank_mms_sku(skuable) raise_if_empty!(mms_sku_to_param(skuable)) [MMS_SKU_PREFIX, mms_sku_to_param(skuable).to_s].join(DELIMITER) end def decorated_mms_sku(skuable) raise_if_empty!(mms_sku_to_param(skuable)) [MMS_SKU_PREFIX, mms_sku_to_param(skuable).to_s, MMS_FINISHED_GOOD_SUFFIX].join(DELIMITER) end def purchase_order(purchase_order_id) raise_if_empty!(purchase_order_id) [PURCHASE_ORDER_PREFIX, purchase_order_id.to_s].join(DELIMITER) end def sales_order(sales_order_id) raise_if_empty!(sales_order_id) [SALES_ORDER_PREFIX, sales_order_id.to_s].join(DELIMITER) end def work_order(work_order_id) raise_if_empty!(work_order_id) [WORK_ORDER_PREFIX, work_order_id.to_s].join(DELIMITER) end private def raise_if_empty!(arg) raise InvalidIdentifier, 'Identifier argument cannot be empty' if arg.to_s == '' end def mms_sku_to_param(skuable) if skuable.respond_to?(:to_param) skuable.to_param elsif skuable.respond_to?(:id) skuable.id else skuable end end end end end