Spain's four-time Grand Slam winner beat Alex de Minaur in three sets to claim his 17th ATP Tour title and his first indoors.