Joint inference of evolutionary transitions to self-fertilization and demographic history using whole-genome sequences