WASHINGTON — President Trump asserted Wednesday that he had the right to enact his travel ban.

He told a group of police chiefs that his immigration order was “done for the security of our nation,” that it was written “beautifully” and that it was within his executive authority.

“A bad high school student would understand this,” he said, adding, “Courts seem to be so political.”

Earlier Wednesday, Trump tweeted that if he loses the court case, the country “can never have the security and safety to which we are entitled.”

The president also tweeted that “if the U.S. does not win this case as it so obviously should, we can never have the security and safety to which we are entitled. Politics!”

A federal judge has put the ban on hold, and the 9th U.S. Circuit Court of Appeals is weighing the appeal of Trump’s executive order on immigration, including a temporary travel ban on those from seven Muslim-majority countries. In arguments before the court Tuesday evening, judges challenged the administration’s claim that the ban was motivated by terrorism fears, but it also questioned an attorney’s argument that it unconstitutionally targeted Muslims.

Trump is expected to have lunch Thursday with a group of moderate Senate Democrats who could play a key role in his legislative agenda.

The lunch is expected to include Sens. Joe Manchin of West Virginia, Heidi Heitkamp of North Dakota, Joe Donnelly of Indiana and Jon Tester of Montana.

Trump faces a narrow Republican majority in the Senate and hopes to secure some support among Democrats for his agenda and the confirmation of Supreme Court nominee Judge Neil Gorsuch. All four Senate Democrats face re-election in 2018.