The 30-plus years thing is one of those writers' accidents: the TNG writers' guide said that he'd commanded the Stargazer with immense success for 22 years, implying it was immediately prior to TNG, and the reason why he'd been given the Enterprise.Thirty plus years is a very long time! It's long enough to be the captain of five or six consecutive ships... It's hard to believe that after such a long time doing nothing, they gave him the command of the most advanced ship in star fleet. That wouldn't make much sense.
Then 10-ish episodes in, The Battle established that Stargazer was lost nine years before TNG, but the 22-year line in the guide remained in and was assumed [even if the writers had wanted to change it, the writers' guide was out there in fandom], even if it was maybe never explicitly mentioned onscreen (think it was, but without checking I may be transferring my fanon assumptions...).
Hence the later hints that maybe Picard took over as Stargazer CO in some emergency that killed his superiors, and all that, which would have made him Stargazer's acting CO very very young, but not necessarily a captain in rank until Starfleet confirmed it and promoted him.
I could see his Stargazer career going something like
Lt-Cdr Picard, Second Officer (newly promoted and transferred)
Lt-Cdr Picard, acting Captain (following deaths of captain and first officer).
Commander Picard, confirmed as Captain by Starfleet in view of recent service and promoted accordingly (given that a small ship like Stargazer could be COed by a commander).
Captain Picard, CO Stargazer, promoted after several years of exemplary service in that role.
And then, eventually, Captain Picard, mandatory court martial for loss of USS Stargazer pending...
But after the court martial, why would their next move be to promote him as captain of the Enterprise? That's what I have a hard time understanding. It would make more sense if there was at least another ship in the meantime. I mean, the Star gazer was a rust bucket compared to the Enterprise.