He is based on a real person who ruled Poland from 1648-1668.
His real name was John II Casimir Vasa (Polish: "Jan II Kazimierz Waza"). He was a member of the House of Vasa - a noble family, ironically, of Swedish origin - and was also the last Polish monarch from that house as well as the last member of the Vasa dynasty via the agnatic line because his only son died in infancy.
Jan Kasimir was once made a cardinal and served until October of 1647, when he resigned to stand in elections to the Polish throne, which he abdicated in 1668. He then went to France to join the Jesuits and became an abbot of Abbey of Germain-des-Pres in Paris, where he died in 1672 at the age of 63.