Lease end purchase or lease transfer as part of trade in?

State: CT
I have 3 payments left on my lease(365/month)of 2020 Mazda Miata RF, mileage 17k. Lease residual is 19900. But I’m thinking of using it as a trade in for a few car.
If I buy out ct tax is 6.35% (1263) so total of 21163. Carmax offered me 25k so a new gain of about 3800.
Or can I use it as part of trade in for the new car and if so, how much should I demand from the dealer?

A post was merged into an existing topic: “Should I buy out my Lease” super thread