Control of oxidation and spin state in a single-molecule junction