Microscopic theory of cavity-enhanced interactions of dipolaritons