A general Bayesian framework for foreground modelling and chromaticity correction for global 21 cm experiments