Juan Martin del Potro handed Roger Federer his first loss of the year with victory in the BNP Paribas Open final at Indian Wells.