A Macroeconomic Approach to Optimal Unemployment Insurance: Theory