Resident doctors in Wales agree new contract with pay rise and improved study leave