Questions about AHL and NHL relationship. I apologize for not being well versed in pro-sports matters.

Do all AHL players get drafted/sign contracts with their NHL affiliates first and then simply get assigned to the farm until the NHL team is in need of a player or has thoroughly impressed the coaching staff? Could all NHL team member theoretically play for their AHL affiliate or does that depend on their contract/number of games played in NHL? Thanks