Ab initio study of Ga-GaN system: Transition from adsorbed metal atoms to a metal–semiconductor junction