Plea bargaining

Understand the plea bargaining and is it legal?