As the 49ers work towards inking Jimmy Garoppolo to a long-term contract, it would behoove them to develop a long-term plan to protect their future investment.

That involves a retooling of this team’s offensive line, which was shaky at best in 2017 and presents considerable uncertainty at all five of its starting positions in any projection of the not-too-distant future.

General manager John Lynch last discussed plans for his offensive line back in November. At the time, Lynch acknowledged that the 49ers have several areas in need of roster upgrades, but implied that left and right tackle — manned by Joe Staley and Trent Brown — are not on the pressing list.

“There’s a lot of places we need to improve and you’re always trying to improve,” Lynch said. “But those two guys are cornerstones for the next few years.”

But since Lynch made those comments, Brown went under the knife for shoulder surgery, and his recovery is expected to take about six months. Meanwhile, Staley hasn’t gotten any younger. He’ll be 34 years old when the 2018 season kicks off.

So, at the very least, this unit’s foundation is on more tenuous ground because of Brown’s situation; and since dominant tackles are rare and valuable, that’s a position where the 49ers should start maneuvering for the future — perhaps as early as this offseason.

Even if the team stands pat at tackle in the coming months, it’ll be forced to take action along the interior line, where center Daniel Kilgore and right guard Brandon Fusco are both pending free agents.

The 49ers will likely use a combination of free agency, the draft, and in-house efforts (2016 first-round pick Joshua Garnett has been reworking his body as he guns for a 2018 starting spot at guard) to immediately revamp the inside.

They might also merge those efforts with a longer-haul revision at tackle. How might that all work out? Let’s begin by identifying specific needs through an overview of the offensive line’s 2017 performance:

49ers OL: Performance Overview (FO and PFF) Category 2017 49ers NFL Rank Adj. Line Yards Per Rush 4.16 11 Power Success Rate 62% 20 Stuff Rate Allowed 23% 25 QB Pressure Rate Allowed 35.7% 15 Adj. Sack Rate Allowed 6.8% 18

Adjusted Line Yards Per Rush is an advanced metric from Football Outsiders (FO) that’s based on yards per carry. The difference from the standard average measurement: This one docks extra value from offensive lines for runs that end in losses while also simultaneously de-emphasizing rushing yardage accumulated further downfield, since it tends to be less correlated with a line’s blocking quality.

By this overall metric, whose formula is explained in detail here, the 49ers offensive line paved the way for a decent 4.16 adjusted line yards per rush, ranking 11th in the NFL.

But the other run-blocking numbers aren’t as rosy, and they’re indicative of a line that leaked negative plays and struggled to execute the job when defenses knew the run was coming.

Power Success Rate, also from FO, is the percentage of third- and fourth-down runs with less than two yards to go that ended in a first down or a touchdown. There’s definitely room for more sturdiness here: The 49ers succeeded on only 62 percent of these mano-a-mano rushing situations, a particular point of pride for an offensive line. That left them ranked 20th in the NFL.

Stuff Rate, also from FO, measures the percentage of times defenses stopped ballcarriers at or behind the line of scrimmage. At 23 percent — 25th in the league — the 49ers didn’t fare well in this regard, either.

QB Pressure Rate, from Pro Football Focus (PFF), is a measure of pass protection. Here, the 49ers allowed opponents to hurry the quarterback on 35.7 percent of dropbacks, ranking 15th in the league — about average. With Brian Hoyer and C.J. Beathard at the helm, this pressure rate was 36.9 percent. After Garoppolo took over, it lowered to 32.6 percent.

Two primary factors framed this improvement: Garoppolo released the ball quicker than his predecessors, and the offensive line was generally healthier during his five starts in December (though it never was back to 100 percent).

Adjusted Sack Rate, from FO, measures sack totals per pass attempt and adjusts them for down, distance, and opponent. At 6.8 percent (18th in the NFL), the 49ers logged a rate that was worse than average here.

When Garoppolo took over, he mostly masked the line’s pass protection deficiencies. According to PFF, Garoppolo completed 62.3 percent of his passes and averaged 8.3 yards per attempt while under pressure. Both of those figures led the NFL.

In all, these advanced numbers generally corroborate the eye test results associated with this offensive line: The 49ers were leaky up front in 2017, and although Garoppolo was able to disguise many shortcomings, this team must bolster its front to sustain its offensive success.

Here are the individual PFF grades of each 49er starting offensive lineman. Grades are accompanied by an NFL rank for that particular position (Staley and Brown are ranked among tackles, Laken Tomlinson and Fusco are ranked among guards, and Kilgore is ranked among centers):

49ers OL: Individual Grades and NFL Ranks (PFF) Player Overall Run Blocking Pass Blocking LT Joe Staley 87.4 (2) 87.6 (1) 84.1 (9) LG Laken Tomlinson 70.7 (32) 76.2 (21) 51.2 (46) C Daniel Kilgore 51.0 (24) 52.7 (19) 52.1 (25) RG Brandon Fusco 76.0 (21) 74.4 (23) 78.9 (19) RT Trent Brown 79.3 (21) 50.3 (46) 84.7 (7)

Staley remains elite. That’s a striking takeaway here, but it’s also a potentially worrisome one for the 49ers, since these numbers suggest that he shouldered a huge part of the line’s load himself.

Even Brown, whose pass protection was excellent, struggled in run-blocking. In fact, Brown graded out worse than all of the 49er interior linemen in this category — and not one member of that trio came close to registering a stellar mark there.

FO charts how effectively the 49ers ran in specific directions. This data corroborates what PFF indicated above — Staley is this unit’s moneymaker.

49ers OL: Run Success By Direction (FO) Direction Adj. Line Yards NFL Rank Left End 5.31 6 Left Tackle 4.94 5 Middle/Guard 4.12 18 Right Tackle 4.11 14 Right End 2.65 28

The overarching goals, then, are to upgrade the middle, establish better dependability on the right side, and recognize that Staley’s stranglehold on the left can’t last forever.

With Fusco’s contract up and Tomlinson’s play leaving plenty to be desired, the 49ers will presumably acquire at least one new guard this offseason. Whether the team spearheads this process through free agency — Andrew Norwell, Josh Kline, Justin Pugh, and Jack Mewhort are all potential possibilities via this avenue — or through the draft remains to be seen.

A potentially fruitful scenario would combine a productive free-agent pick-up with a resurgence from Garnett, who is working to tailor his body for Kyle Shanahan’s outside-zone running scheme. If those two dominoes fall, the 49ers can suddenly be sitting pretty at guard in 2018.

But neither is a sure bet — especially since even a prized free-agent acquisition would have to mesh with the system.

Furthermore, those two potential upgrades would not address the pair of literally humongous elephants in the room. Staley, who has two more years left on his contract, is projected to enter free agency at age 35, while Brown has only one season left on his rookie deal.

Management will closely monitor Brown’s recovery from shoulder surgery and his subsequent progress on the conditioning front. At 6-8 and 355 pounds, Brown is the NFL’s largest player, and his unsteady run-blocking performance raises questions about his ability to move in space effectively enough for the outside-zone attack.

Although the 49ers are certainly enamored with Brown’s pass-blocking capabilities, which have come a long way since Brown was drafted as a raw seventh-rounder in 2015, the team will need to see overall post-injury improvement before offering him a long-term extension.

Staley, meanwhile, has repeated that he wants to retire as a 49er, and he should get that opportunity as long as his play remains this effective. Still, the prospect of excellence at left tackle beyond age 35 is nothing to take to the bank.

And since the NFL tackle spots are positions that typically require a period of refinement for youngsters to reach true success, the 49ers may opt for a head start here in this year’s draft.

They can actually combine this effort with the push to fortify the interior of the line. Several tackles in the 2018 crop, including Oklahoma’s Orlando Brown, Georgia’s Isaiah Wynn, Texas’ Connor Williams, and Oklahoma State’s Zachary Crabtree project positional versatility (though Wynn, at only 6-2, may ultimately be undersized for the tackle position).

So, if the 49ers use one of their higher picks on a future tackle, they may be able to immediately plug him into a starting role at guard, a move that could kill two birds with one stone. In theory, they can simultaneously address short-term and long-term needs.

They 49ers may be able to surf a similar wave of adaptability at center. Because of the position’s cerebral nature, the aforementioned advanced blocking metrics may not be quite as indicative of value here. Garoppolo has indicated he wants Kilgore retained because of the pre-snap chemistry the duo has developed. But an upgrade remains appealing.

Shanahan, after all, enjoyed the services of Alex Mack — widely considered the NFL’s top center — while building the league’s most productive offense in Atlanta two years ago.

The Falcons have Mack under contract through 2020, so he’s unlikely to rejoin Shanahan anytime soon. But the coach may opt to draft a player like Ohio State’s Billy Price, who projects as both a guard and a center at the NFL level. Under that scenario, the 49ers could theoretically re-sign Kilgore to a short deal and immediately plug Price, their potential center of the future, into a guard position for the time being.

Of course, the 49ers can also focus more on development by drafting a player like West Georgia’s Desmond Harrison — an East Bay native. At 6-8, he has prototypical size for a tackle, but Harrison is a raw talent like Brown was in 2015, so he may be around during the draft’s later rounds.

More than anything, the 49ers stand to benefit in the near future from building quality depth along the offensive line. While opponents thrashed Beathard during the great injury rash of 2017, Shanahan certainly longed for a better stash of offensive linemen. This offseason is a chance to stockpile just that along the line for 2018 and for the franchise’s longer-term future.

Given Garoppolo’s value and likely eye-popping price tag, success on this front — insurance for the big investment — is a necessity.

Garoppolo agrees. At Christmas, the quarterback gifted every 49er offensive lineman — even those on injured reserve and the practice squad — a set of Bose headphones.

“The O-linemen, they’re my guys,” Garoppolo said at the time. “I’ve gotta take care of my guys.”

Now, the 49ers must take care of the offensive line, so that they can return the favor for Garoppolo on the field.

(Top photo: Michael Zagaris/San Francisco 49ers/Getty Images)