text: import persistable_object_utils from '../../DocumentPersister/persistable_object_utils'
  
  const CollectionName = 'FundsRequests'
  //
  // Utility functions
  function HydrateInstance (
    instance,
    plaintextDocument
  ) {
    const self = instance
    //
    // console.log("plaintextDocument", plaintextDocument)
    function _isNonNil_dateStr (v) {
      return v != null && typeof v !== 'undefined' && v !== ''
    }
    {
      const dateStr = plaintextDocument.dateCreated
      self.dateCreated = _isNonNil_dateStr(dateStr) ? new Date(dateStr) : null
    }
    self.from_fullname = plaintextDocument.from_fullname
    self.to_walletHexColorString = plaintextDocument.to_walletHexColorString
    self.to_address = plaintextDocument.to_address
    self.payment_id = plaintextDocument.payment_id
    self.amount = plaintextDocument.amount
    self.amountCcySymbol = plaintextDocument.amountCcySymbol
    self.message = plaintextDocument.message
    self.description = plaintextDocument.description
    self.is_displaying_local_wallet = plaintextDocument.is_displaying_local_wallet
  }
  //
  function SaveToDisk (
    instance,
    fn
  ) {
    const self = instance
    // console.log('📝  Saving fundsRequest to disk ', self.Description())
    {
      fn = fn || function (err) { console.error(err); console.trace('No fn provided to SaveToDisk') }
    }
    const persistencePassword = self.persistencePassword
    if (persistencePassword === null || typeof persistencePassword === 'undefined' || persistencePassword === '') {
      const errStr = '❌  Cannot save fundsRequest to disk as persistencePassword was missing.'
      const err = new Error(errStr)
      fn(err)
      return
    }
    { // defaults/onces
      if (typeof self.dateCreated === 'undefined') {
        self.dateCreated = new Date()
      }
    }
    const plaintextDocument =
  	{
  	  dateCreated: self.dateCreated.toString(), // must do toString else we will get exception on encrypting
  	  //
  	  from_fullname: self.from_fullname || '',
  	  to_walletHexColorString: self.to_walletHexColorString || '',
  	  to_address: self.to_address,
  	  payment_id: self.payment_id,
  	  amount: self.amount != null && self.amount != '' ? '' + self.amount : self.amount, // storing this as an optional String
  	  amountCcySymbol: self.amountCcySymbol,
  	  message: self.message || '',
  	  description: self.description || '',
  	  is_displaying_local_wallet: self.is_displaying_local_wallet == true
  	}
    persistable_object_utils.write(
      self.context.persister,
      self, // for reading and writing the _id
      CollectionName,
      plaintextDocument, // _id will get generated for this if self does not have an _id
      persistencePassword,
      fn
    )
  }
  //
  function DeleteFromDisk (
    instance,
    fn
  ) {
    const self = instance
    // console.log('📝  Deleting fundsRequest ', self.Description())
    self.context.persister.RemoveDocumentsWithIds(
      CollectionName,
      [self._id],
      function (
        err,
        numRemoved
      ) {
        if (err) {
          console.error('Error while removing fundsRequest:', err)
          fn(err)
          return
        }
        if (numRemoved === 0) {
          fn(new Error("❌  Number of documents removed by _id'd remove was 0"))
          return // bail
        }
        // console.log('🗑  Deleted saved fundsRequest with _id ' + self._id + '.')
        fn()
      }
    )
  }
  export default { CollectionName, HydrateInstance, SaveToDisk, DeleteFromDisk }
  