After US citizen Rizwan Farook and his Pakistani wife Tashfeen Malik murdered 14 people in San Bernardino on December 2, 2015, Donald Trump called for a "total and complete shutdown of Muslims entering the United States."

Trump tweaked the plan, but never abandoned it. He later rephrased it as suspending “immigration from terror-prone regions where vetting cannot safely occur,” vowing to implement it on his first day in office. This covers immigration only, not tourist or student visas, and isn’t explicitly a religious test. But everyone knows where “terror-prone regions” are, and who lives there.

Candidate Trump was never particularly specific on the policy details of how the Muslim ban would work. But with President-elect Trump set to take office in January, and his pledge to implement the ban on day one now about to be put to the test, the question looms: Will he be able to do it, and if so, how?

I put that to several experts on US immigration law. Their answer was unanimous: Trump would be able to implement his ban. In fact, he would be able to do it easily. Congress has already granted wide power to the president to alter immigration rules, so he will not need congressional approval. If the ban is designed properly, it is virtually guaranteed to survive court challenges from liberal advocacy groups determined to derail it.

The consequences of implementing such a ban, the experts warned, could be very bad. America’s reputation in the world, its economy, and even its struggle with militant groups like ISIS would all suffer. The ban would be a slap in the face to America’s basic commitment to the equal treatment of all people, regardless of their faith or background, and to welcoming in the downtrodden. In the aftermath of Tuesday’s upset, many Muslim Americans are openly wondering whether they will be safe in Trump’s America.

My mom literally just texted me "don't wear the Hijab please" and she's the most religious person in our family.... — ㅤ (@harryonmen) November 9, 2016

But given the state of the law, everything hinges on Donald Trump deciding that those potential problems override what he appears to see as a way of improving American national security.

The president has nearly unchecked authority to ban people from entering the country

In 1952, Congress passed something called the Immigration and Nationality Act. It has been amended dozens of times subsequently, and currently exists as a 600-page behemoth with lots of very specific rules.

There is one section, 212(f), that is particularly relevant to the Muslim ban. It sets out criteria for “excludable aliens” — which noncitizens the president can choose, using executive powers, to prevent from entering the United States. Its wording is exceptionally broad:

Whenever the President finds that the entry of any aliens or of any class of aliens into the United States would be detrimental to the interests of the United States, he may by proclamation, and for such period as he shall deem necessary, suspend the entry of all aliens or any class of aliens as immigrants or nonimmigrants, or impose on the entry of aliens any restrictions he may deem to be appropriate.

Translated from legalese: The president can ban whoever he wants, however long he wants, for whatever reason he wants.

“All he has to do is say ‘I think Muslims are not in the interests of the United States,’” says Stephen Legomsky, a professor emeritus at Washington University School of Law in St. Louis and the former chief counsel for US Citizenship and Immigration Services.

The formulation that Trump initially used on the campaign trail might not survive a court challenge. The First Amendment has some very clear things to say about religious discrimination, and no president has ever attempted to use 212(f) to implement a religious test on migration. A ban phrased that bluntly could very well be overturned.

“I think there would be a serious constitutional question as [a ban] specifically based on religion would violate the establishment clause of the Constitution,” Legomsky says.

This is where Trump’s new phrasing, based on nationality, comes into play. Nationality, as my colleague Dara Lind explains, is not a constitutionally protected class like religion. If Trump wanted to exclude anyone who’s a Saudi or Pakistani national from entering the United States, the First Amendment wouldn’t be a barrier.

And indeed, it’s quite explicitly legal for the president to discriminate in immigration policy, under something called the “plenary power” doctrine. This basically says that the court should grant extreme deference to the executive when it decides to exclude non-citizens from entering the country, and that non-citizens don’t have equal protection rights in the way that citizens do.

“The [Supreme] Court quickly came to the conclusion that the judiciary had little or no role in reviewing decisions prohibiting foreigners from entering the country, nor in reviewing decisions to arrest, detain, and deport non-citizens who were already inside the country,” Michael Kagan, a law professor at the University of Nevada-Las Vegas, writes.

So if Trump sticks with his newer formulation, and structures the ban around regions of the world or specific countries, it’s extremely unlikely that any court would stop him.

“It’s pretty easy for him to get at what he was [originally] talking out within legal parameters,” Marshall Fitz, managing director of the pro-immigration Emerson Collective, tells me. “To make it excessively difficult for Muslims, for people from certain regions of the world, from certain countries to enter.”

Here’s what Trump’s Muslim ban would actually look like

How would Trump’s Muslim ban work in practice?

One very simple way, according to the experts, is that he could deny anyone who holds a passport from certain countries from entering the United States. He has never been clear on which countries, exactly, would qualify — whether you need to be a Muslim-majority country, or merely have a large Muslim population, or literally be limited to countries that have experienced or been tied to terror attacks.

Regardless of which countries are included, the system would be very simple: If you’re using a Saudi passport, or an Iraqi one, or a Pakistani one, or an Indonesian one — sorry, no immigration into America for you.

This system, though, would be a bit broad — and might end up banning people Trump would want to admit. This includes Iraqi Christians, computer engineers from Muslim-majority countries hired to code at Silicon Valley firms, or a foreign scholar hired to teach at an American university. If the ban extends beyond immigration, and includes tourists or business travelers, it could ban representatives from some of America’s key allies from even stepping foot in the country.

“The easiest way to implement it, the least bureaucratically difficult, would be a nationality-based system,” Theresa Cardinal Brown, the director of immigration policy at the Bipartisan Policy Center, says. “Of course, that would mean that if you’re a Christian from that country, or someone else, you could also be part of that.”

Presumably, evangelicals would bristle at banning Syrian Christians fleeing ISIS from entering the country. So Trump might, for political reasons, want to create exceptions to the ban. This is tricky, because most countries don’t list religion in their passports.

The way around this problem is to structure the ban a bit more subtly. Instead of outright saying “ban Iraqi immigration,” you could impose additional requirements on anyone trying to emigrate from those countries — barriers that are so onerous that immigration from these countries would be virtually impossible

One example, Fitz says, is requiring “multiple, non-delegable Cabinet level signatures that an individual does not pose a threat to the United States.” Making the attorney general and the secretary of homeland security personally sign off on every entry from a Muslim-majority country would effectively end immigration from those places.

“Even getting one such certification directly from a Cabinet-level secretary would probably be sufficient to bar people,” Fitz says. “What secretary has time, bandwidth, [or] resources to individually … certify that someone is not a security threat?”

This would avoid the appearance of formally banning non-Muslims from Muslim countries, while in effect accomplishing the same thing. It would be as bureaucratically easy to implement: If you have a passport from a banned country, and don’t have a permission slip from Attorney General Rudy Giuliani, then you can’t immigrate. And to top it all off, Fitz says, it would be constitutionally ironclad.

There are other ways to accomplish the same goal without simply saying “ban Muslims.” Trump could cut staffing resources and funding in State Department offices that cover specific countries, so it would take an incredibly long time to process any immigration requests. He could also make the vetting requirements even more onerous than it already is for potential immigrants from Muslim, to the point where it would be impossible for anyone to satisfy the kind of examination he wants.

Trump could ban immigration from Muslim countries, and he could do it easily.

The ban would be a disaster

While the ban might be easy to do, as a matter of policy, it is not a very good idea.

“The consequences of doing this could be significant,” Brown says. “And that’s where the rubber hits the road.”

For one thing, the US gets a lot of money from immigrants and tourists from the Muslim world. Either by settling in and contributing to the US economy, or by simply visiting and spending their money here, they put dollars in the pockets of American consumers and the US government.

The costs to specialized industries like technology, which need to attract top notch talent whenever it’s available, could be severe: Steve Jobs, as you might know, was the son of a Muslim immigrant from Syria. It’s hard to put a precise figure on how many would-be Silicon Valley employees would be impacted, since no reliable estimates exist of how many Muslims would be denied entry or would choose not to visit, but the damage to American firms in one of the most competitive industries in the world could be severe.

More fundamentally, the Muslim ban would screw up the entire global migration system.

International migration depends on something called “reciprocity:” the idea that if I let your people visit and migrate to my country, you let my people visit and migrate to yours. Countries are free to limit the absolute number of migrants, but putting onerous restrictions on travel and banning people from one place altogether is generally considered a no-no.

This can lead to retaliation against the country imposing the rules. In the wake of 9/11, for example, the US set up a fingerprinting requirement for foreigners entering the country. Brazil, annoyed at the hassle to its citizens, retaliated, imposing a fingerprinting requirement on Americans entering Brazil. This is how reciprocity works: You limit our citizens’ freedoms, we limit yours’.

Banning people from a truly diverse range of countries could very well provoke serious retaliation. Remember, there are 1.6 billion Muslims around the world. Using nationality as a blunt tool to ban Muslim immigration would punish a hell of a lot of countries. Three of the world’s 20 largest economies — Saudi Arabia, Indonesia, and Turkey — have Muslim majorities (as well as terrorism problems).

You could easily imagine these countries placing restrictions on American travel in retaliation — or impose other kinds of restrictions on American trade and business with their countries.

The potential costs of are incalculable. In a global economy, American corporations depend on being able to send their people wherever they need to go to function, and on exports to foreign markets. If, say, Indonesia responds to a Muslim ban by limiting US travel or restricting American corporations’ rights to operate, this would cause serious damage to the US economy.

“You start to deny admissions of people from certain countries or regions, and how do they respond? Do they respond by declining to engage in certain kinds of economic activity with the United States? Do they start to bar US corporations from operating in that region?” Fitz asks, rhetorically. “You can imagine, quickly, how the kind of standoff could escalate.”

There are national security implications, too.

A lot of these Muslim-majority countries are key partners in America’s counter-terrorism campaigns. In places like Saudi Arabia and Jordan, the US depends on partnerships with local security officials to get intelligence on extremist activity. Washington desperately wants Pakistan, meanwhile, to honor its past promises to protect its nuclear arsenal and allow American drones to operate in its skies.

What happens to that cooperation in a world where the United States is openly discriminating against their citizens? And how much more successful does ISIS and al-Qaeda recruiting propaganda, which depends on casting the US as an enemy of Islam, become?

This is all to say nothing of the morality of treating people as potential terrorists, based solely on their nationality or religion — how much it contravenes what we see as bedrock American values of tolerance and openness. We’ve violated these principles many times before — think of the Chinese Exclusion Act of 1882, which did exactly what it sounds like.

But a lot of Americans thought we were past that. It’s up to Donald Trump to decide whether they were right.

Watch: It’s now on America’s institutions to check Trump