Optimal debt contracts and moral hazard along the business cycle