A theory for model-based nonsmooth optimization