New York CNN Business  — 

Tesla filed suit Saturday night against Alameda County, California, after local officials there refused to let the company reopen its Fremont factory.

In a series of tweets earlier Saturday, Tesla CEO Elon Musk also threatened to move the company’s headquarters to Texas or Nevada, where shelter-in-place rules are less restrictive.

“Frankly, this is the final straw. Tesla will now move its HQ and future programs to Texas/Nevada immediately,” Musk tweeted. Tesla did not respond to a request for comment on Saturday.

The lawsuit follows months of Musk tweeting debunked and controversial coronavirus claims — and railing against stay-at-home orders — often contrary to health officials’ guidance.

The automaker had planned to allow a fraction of its factory workers to return to work by Friday, but was warned by the Alameda County Health Department in a livestreamed town hall on Friday that such a move would be violating the county’s rules.

“This has been a collaborative, good faith effort to develop and implement a safety plan that allows for reopening while protecting the health and well-being of the thousands of employees who travel to and from work at Tesla’s factory,” the Alameda Health Department responded on Saturday in a statement to CNN Business. “The team at Tesla has been responsive to our guidance and recommendations, and we look forward to coming to an agreement on an appropriate safety plan very soon.”

California Gov. Gavin Newsom had issued new guidance Thursday allowing manufacturing companies to reopen, which allowed individual counties to enforce stricter rules. Alameda County’s shelter-in-place rule ends on May 31. Texas set a May 18 date for manufacturers to resume limited operations, while Nevada allowed many retailers and nonessential businesses to reopen Saturday.

“We’ve been working with [Tesla], but we have not given the green light,” Alameda County Health Officer Erica Pan said during Friday’s town hall. “We have not said it is appropriate to move forward.”

At least one California assemblywoman wasn’t having it. Lorena Gonzalez, who represents San Diego, tweeted an obscenity at Musk.

Tesla’s lawsuit, filed Saturday evening in federal court in California’s Northern District, asks for a permanent injunction barring the county from enforcing its shelter-in-pace order. The company said it believed it is exempt because its operations fall within the definition of critical infrastructure.

Tesla has a battery factory, called Gigafactory 1, in Sparks, Nevada, but it has no footprint in Texas. In February, Musk took a Twitter poll asking his followers if there should be a Gigafactory in Texas. The results were 80% positive.

On Saturday, Musk also encouraged Tesla shareholders to file a class action lawsuit against the county for any money lost given that Tesla competitors in other states could resume their operations earlier. He said that Tesla should be allowed to reopen because it learned how to deal with Covid-19 through its factory in Shanghai, China, which is currently the company’s only operating plant.

Republican Sen. Ted Cruz of Texas tweeted Saturday, “Come to Texas! We would welcome Tesla HQ in Texas. We love jobs & Texans very much want to open up & get back to work (while still staying safe & following sound science). We make lots of cars & trucks in Texas, and we’d love more!!”