Controlling the interfacial reactions and environment of rare-earth ions in thin oxide films towards wafer-scalable quantum technologies