Villagers (and their villages) have changed a lot since their origins. At first, they shared their AI with PIGS! Eventually, they were given the ability to trade with players. The trading mechanics were heavily revamped in the 1.14 Village & Pillage update. In post-1.14 versions, you can cure villagers or save them from raids to get better deals. You can change their job and things for sale by breaking and placing their workstation. In pre-1.14 versions, you can rade with them. That's kinda it. In any version (after trading was added) you can trade with vilagers by right clicking/holding your finger/pressing the left trigger while sfacing them. You can give them items for emeralds and trade those emeralds for items. You can unlock new trades from them by trading with thta perticular villager. The houses and farms are also full of resources you can steal.
A post-1.14 village