Tesla sued local authorities in California as the company tried to reopen a factory there and CEO Elon Musk threatened to move Tesla’s headquarters and future programs from the state to Texas or Nevada.

Musk has been pushing to restart Tesla’s Fremont, California, factory after Alameda County’s health department said the company must not reopen because local lockdown measures to curb the spread of the coronavirus remain in effect.

In a blog post on Saturday, Tesla said the county’s position left it no choice but to take legal action to ensure Tesla and its employees can go back to work.

The company said it had worked out a thorough return-to-work plan that includes online video training for personnel, work zone partition areas, temperature screening, requirements to wear protective equipment and rigorous cleaning and disinfecting protocols.

Tesla said it had informed health authorities in Alameda County, where the Fremont factory is located, about its restart plans, but claimed the acting official did not return calls or emails.

Alameda County’s Public Health Department, which earlier on Saturday said it had been “communicating directly and working closely with the Tesla team,” did not immediately respond to a request for comment.

Tesla filed a lawsuit against the county in San Francisco federal court on Saturday, calling the continued restrictions a “power-grab” by the county since California’s governor had said on Thursday that manufacturers in the state would be allowed to reopen.

The company said Alameda was going against the federal and California constitutions, as well as defying the governor’s order, the lawsuit said.

Musk told employees on Thursday that limited production would restart at Fremont on Friday afternoon.

California Governor Gavin Newsom said on Thursday that manufacturers in the state would be allowed to reopen.

Alameda County is scheduled to remain shut until the end of May, with only essential businesses allowed to reopen. The county said it does not consider Tesla an essential business. County officials did not immediately respond to a request for comment on the lawsuit.

The outspoken Musk also took to Twitter on Saturday to complain and threatened to leave the state.

“If we even retain Fremont manufacturing activity at all, it will be dependen (sp) on how Tesla is treated in the future,” he tweeted, referring to the San Francisco Bay area facility that is Tesla’s only U.S. vehicle factory.

Alameda County said on Saturday that it has been working with Tesla to develop a safety plan that “allows for reopening while protecting the health and well-being of the thousands of employees” that work at the factory and that it looks forward to coming to an agreement on a safety plan very soon.

Fremont Mayor Lily Mei expressed concern about the potential economic implications of continuing the shelter-in-place order without provisions for manufacturers such as Tesla to resume. Mei on Saturday urged the county to work with businesses on “acceptable guidelines for re-opening.”

Musk had told employees on Thursday that limited production would restart at Fremont on Friday afternoon.

The threat to relocate the facility comes as Tesla aims to ramp up production at Fremont of the Model Y crossover, which it expects to generate record demand and profit margins.

Musk, who sparred with California officials in March over whether Tesla had to halt production at Fremont, had criticized the lockdown and stay-at-home orders, calling them a “serious risk” to U.S. business and “unconstitutional.”

Tesla builds more than 415,000 EVs per year at the Fremont plant and moving the entire production facility would be a massive undertaking.

Dan Ives, a Wedbush analyst, on Saturday estimated it could take the company 12 to 18 months to relocate production.

The tweets raise pressure on Newsom and San Francisco Bay area officials who were among the first in the U.S. to implement shelter-in-place orders and have been cautious about lifting them. Musk, 48, has arguably been the tech sector’s loudest voice advocating for the reopening of the economy, which has drawn criticism from some of his peers in the business community and cheers from conservative political circles.

Tesla has roughly 20,000 employees in the region, including its headquarters in Palo Alto. Moving the headquarters and future programs to Texas and Nevada, where Tesla has its massive battery plant, is a threat that would be relatively easier for Musk to follow through on.

The Fremont plant is the only place in the world where Tesla makes the Model S, X and Y, and the company has sunk billions of dollars into the site over the years.

“Picking up and leaving isn’t really an option right now,” Ben Kallo, an analyst at Robert W. Baird & Co., said by phone. “I don’t know if you can quickly say ‘I’m leaving.’”

Musk has been scouting locations for a new U.S. factory to build the Cybertruck and has hinted it could be constructed in Texas, where part of Tesla’s chip team is based. His rocket company Space Exploration Technologies Corp. also has operations in the state.

Missouri also has been making a pitch for the plant.

Tesla shares have risen 127 percent since March 18, their recent closing low, including a 17 percent gain in the last trading week to close at $819.42 on Friday.