Settlements of lawsuits have become common between branded-drug makers and their generic-drug counterparts -- Pfizer (NYSE:PFE) did it just last week -- but the agreement between Barr Pharmaceuticals (NYSE:BRL) and Bayer may have set a record for the most complex.

Let me break it down for you, because there's something in it for everyone.

Barr won a lawsuit invalidating Bayer's patent on its birth control, Yasmin, back in March, but Bayer turned around and filed an appeal with a higher court. If Barr launches its generic version of Yasmin now, it could be on the hook for damages if Bayer wins the appeal.

The agreement announced Tuesday removes that risk for Barr, and Bayer gets manufacturing and royalty payments from Barr. If Bayer does end up winning the appeal, Barr would have to pay a higher royalty rate, but would still get to sell the product. Like I said, something for everyone.

As an added bonus, Barr gets to launch a generic version of a related birth control pill, Yaz, in 2011, which Bayer will supply.

The interesting part is that Bayer will be manufacturing the drug for Barr as an authorized generic. That may seem a bit odd, but there's a method to Barr's madness. Because Barr has the 180-day exclusive period for Yasmin, the Food and Drug Administration won't approve any other generics until 180 days after Barr launches its own version of Yasmin or the date of a final court decision finding the patent invalid, whichever comes first. Because Barr will sell Bayer's version of Yasmin rather than its own, the FDA will wait until 180 days after the ruling on the appeal is made before approving Novartis' (NYSE:NVS) and Watson Pharamceuticals' (NYSE:WPI) generic versions of Yasmin. Given the speed with which the courts move, that could be years from now.   

While the deal looks complicated, it's definitely a shrewd move by Barr. The Stock Advisor pick will have to give up some profits now, but the authorized-generic aspect of the deal should allow it to recoup that loss over the long term.

For more Foolishness: