A Macroeconomic Theory of Optimal Unemployment Insurance