-- * Duplicate detection

-- | Returns True if this transaction is not a duplicate.
freshPosting
  :: OfxIn
  -- ^
  -> OfxOut
  -- ^
  -> Map Account (Set Text)
  -- ^
  -> Bool
freshPosting inp out lkp = case Map.lookup acctName lkp of
  Nothing -> True
  Just set -> not $ Set.member fitid set
  where
    acctName = _foreignAccount out
    fitid = X.pack . OFX.txFITID . _ofxTxn $ inp


-- | Given a sequence of filenames and the text that is within those
-- files, returns a map.  The keys in this map are all the accounts,
-- and the values are a set of all the fitids.  Also, if the sequence
-- of filenames is non-empty, returns the last filename, and its
-- corresponding WholeFile.
freshPosting
  :: OfxIn
  -- ^
  -> OfxOut
  -- ^
  -> Map Account (Set Text)
  -- ^
  -> Bool
freshPosting inp out lkp = case Map.lookup acctName lkp of
  Nothing -> True
  Just set -> not $ Set.member fitid set
  where
    acctName = _foreignAccount out
    fitid = X.pack . OFX.txFITID . _ofxTxn $ inp


-- | Given a sequence of filenames and the text that is within those
-- files, returns a map.  The keys in this map are all the accounts,
-- and the values are a set of all the fitids.  Also, if the sequence
-- of filenames is non-empty, returns the last filename, and its
-- corresponding WholeFile.
freshPosting inp out lkp = case Map.lookup acctName lkp of
  Nothing -> True
  Just set -> not $ Set.member fitid set
  where
    acctName = _foreignAccount out
    fitid = X.pack . OFX.txFITID . _ofxTxn $ inp


-- | Given a sequence of filenames and the text that is within those
-- files, returns a map.  The keys in this map are all the accounts,
-- and the values are a set of all the fitids.  Also, if the sequence
-- of filenames is non-empty, returns the last filename, and its
-- corresponding WholeFile.