President Donald Trump can’t just pull funding for high-speed rail from California as payback for the state’s challenging the constitutionality of his border wall.

There are laws governing decisions by agencies like the Department of Transportation. Those laws require that agencies give principled policy reasons for their actions — not recite doubtful pretexts for decisions taken on political grounds.

If the Transportation Department actually pulls the funding, as it has said it plans to do, California will challenge the decision in court. And the odds are pretty high that the state will win, regardless of what happens in the separate legal challenge to the border wall.

At issue in the latest Trump administration shenanigans is a high-cost, high-speed-rail project that is supposed to connect San Francisco to Los Angeles. California voters adopted the plan by referendum in 2008. The total cost would be somewhere in the neighborhood of $77 billion. Last week, Governor Gavin Newsom said the state was pulling back from its ambitious original plan, and will focus on completing one smaller section.

The federal government has already put in about $2.5 billion in grants. An additional $929 million is in the pipeline — or was, until the Department of Transportation sent a letter to the state pulling the funding.

The timing of that letter is crucial not only to understanding what happened but also to predicting the outcome of the future lawsuit.

On Monday, the state of California, joined by 15 other states, filed suit in federal district court to block Trump from using money not allocated by Congress to build a wall along the U.S. border with Mexico. The attorney general of California took the lead. That matters because, by filing suit in California, the states hope to get a liberal lower court judge and to get the case before the U.S. Court of Appeals for the 9th Circuit, which ruled against Trump in the Muslim travel ban case.

On Tuesday, one day after the suit was filed, the head of the Federal Railroad Administration, part of the Department of Transportation, sent a letter to the chief executive of the California High-Speed Rail Authority unilaterally terminating the grant agreement between the department and the state and pulling the $929 million that was otherwise coming.

At the same time, the Department of Transportation issued a statement to the effect that it was “actively exploring every legal option to seek the return from California of $2.5 billion in Federal funds FRA previously granted for this now-defunct project.”

The letter said that the FRA’s decision was “based on many factors.” It listed several, of which the most significant was the assertions that California wasn’t on track to finish the project by 2022. The others involved alleged failures by California to fund the project at agreed-upon levels and to file reports connected to its funding plans.

The letter also gave the state the opportunity to respond to these claims by March 5. The letter said the FRA would consider California’s answers “before taking any final action.”

The timing alone makes the plan to pull the funding look like Trump’s revenge against California. The unusual separate statement about seeking the clawback of $2.5 billion strengthens the circumstantial case.

Then, as usual, there are presidential tweets that come close to sealing the deal. Also Tuesday, Trump tweeted:

The juxtaposition of the California suit with the reference to the expensive high-speed-rail project makes the causal connection seem fairly evident. But Trump wasn’t done. He tweeted:

It’s a foundational principle of law under Administrative Procedure Act that an agency must give reasons for its actions. Those reasons have to be the actual ones the agency has used, not excuses.

Courts have used this principle to strike down other Trump actions. Most recently, a federal district judge in New York blocked the Department of Commerce from adding a citizenship question to the 2020 census on the ground that the commerce secretary had given reasons that were pretext, not accurate representations of his motives.

If the Department of Transportation isn’t bluffing, and actually kills the funds, California can sue under the Administrative Procedure Act.

The only defense available to the Trump administration will be that it had good reason to counsel the funding independent of California’s wall lawsuit — essentially, the federal government will have to argue that it would have made the same decision regardless of California’s lawsuit, and that its reasons are legitimate.

If and when the government raises that defense, its lawyers will have to grapple with Trump’s tweets.

Past presidents wouldn’t have wanted to lose in court. According to convention, it’s supposed to be politically costly for a president to have a judge tell him that he acted vindictively and in violation of federal law.

But as we have learned repeatedly, Trump doesn’t seem to mind losing in court so long as he gets his political message across. In this instance, the message of payback is about as clear as it can get.