David Paul Morris/Bloomberg/Getty Images Michael Flynn, national security adviser to President-elect Donald Trump, now says Turkey is one of America's most critical allies. In July, he cheered for an attempted military coup against its president.

WASHINGTON ― When a faction of the Turkish military attempted to overthrow President Recep Tayyip Erdogan in July, Lt. Gen. Michael Flynn celebrated the coup effort as something “worth clapping for.”

But a Dutch company headed by a man with ties to Erdogan’s government hired Flynn’s intelligence firm about two months later. Since then, Flynn has dramatically reversed his public position on the failed putsch in Turkey. Earlier this month, he wrote a piece in The Hill hailing Erdogan’s Turkey as a critical U.S. ally and calling on the Obama administration to extradite the cleric Ankara has accused of orchestrating the coup.

At the time of the attempted coup, Flynn viewed Erdogan as an Islamist who was leading Turkey down the wrong path. As the violent effort to oust the Turkish president unfolded, Flynn addressed an audience in Cleveland, where he was promoting his book on radical Islam.

“Probably most of you don’t know, but there’s an ongoing coup going on in Turkey right now,” Flynn said during remarks. Turkey, Flynn warned, had begun “to move toward Islamism.”

“This is Turkey under Erdogan ― who is actually very close to President [Barack] Obama,” Flynn said, speaking at the Cleveland chapter of ACT for America, a group that describes itself as “the [National Rifle Association] of national security.”

“If the military succeeds,” Flynn continued, “one of the things that the military immediately said is, ‘We recognize our responsibilities with NATO, we recognize our responsibilities with the United Nations, we want to make sure that the world knows, we are, we want to be seen as a secular nation.’” The audience cheered.

“That is worth clapping for,” Flynn said.

By the next day, it was clear the attempted coup had failed ― in part because even Erdogan’s critics in Turkey preferred his increasingly authoritarian rule to a military takeover.

In the months since, Erdogan has used the event as justification to further consolidate his power. He has also accused Muslim cleric Fethullah Gulen of orchestrating the putsch from Pennsylvania, where he lives in self-imposed exile. Ankara has pushed Washington to extradite Gulen, but he denies orchestrating the coup and the Department of Justice has said it doesn’t have sufficient evidence to send him back.

These days, Flynn, who was recently named national security adviser to President-elect Donald Trump, is pushing a different view on Turkey’s president and the July effort to oust him.

“We need to see the world from Turkey’s perspective,” Flynn wrote in a piece published on Election Day. “We must begin with understanding that Turkey is vital to U.S. interests. Turkey is really our strongest ally against the Islamic State in Iraq and Syria (ISIS), as well as a source of stability in the region.”

From Turkey’s point of view, Flynn wrote, failing to extradite Gulen is like “harboring Turkey’s Osama bin Laden.” He compared Gulen to Sayyid Qutb and Hasan al Banna, leaders of the Muslim Brotherhood, and to Ayatollah Ruhollah Khomeini, who led the 1979 Islamic Revolution in Iran.

In a stark reversal from his July comment about Obama and Erdogan’s closeness, Flynn accused the Obama administration of “keeping Erdogan’s government at arm’s length ― an unwise policy that threatens our long-standing alliance.”

In his contribution to The Hill, Flynn failed to disclose that his intelligence firm had recently inked an agreement with a Dutch consulting group headed by a businessman who has ties to the Turkish government.

Lobbying registration paperwork filed in September shows that Flynn Intel Group was hired by Inovo BV, a company founded by Kamil Ekim Alptekin. Alptekin is the chairman of the Turkish-American Business Council and helped arrange Erdogan’s visit to Washington earlier this year. Robert Kelley, Flynn Intel Group’s chief counsel, is the group’s registered lobbyist. According to the paperwork, Inovo BV hired Flynn’s firm to provide advice on funding bills for the Departments of State and Defense. The Daily Caller was the first to report on the lobbying registration.

While Flynn is not himself a lobbyist, Alptekin told The Intercept that Inovo BV paid Flynn’s company “tens of thousands of dollars” for world affairs analysis. Alptekin said he has met Flynn but does not have influence over his views.

It's problematic. Which Flynn are we dealing with? Henri Barkey, The Woodrow Wilson International Center for Scholars

Trump’s transition team has said it will impose a lifetime ban on administration officials lobbying on behalf of a foreign government after leaving government.

Flynn, who ran the Defense Intelligence Agency before being pushed out in 2014, was an early supporter of Trump’s presidential bid. Well-respected by his peers during his military career, he has made a series of startling comments since retiring.

“Fear of Muslims is RATIONAL,” Flynn tweeted in February. While campaigning for Trump, he led chants of “lock her up” against Democratic presidential nominee Hillary Clinton. The former DIA chief has encouraged his fans on Twitter to follow conspiracy theorist Mike Cernovich.

Despite his inflammatory rhetoric, Flynn, with his decades of military experience, was considered by many to be one of the more serious individuals in the national security arena to endorse Trump. But his comments from July, juxtaposed with his recent opinion piece and his firm’s lobbying ties to Erdogan, suggest that the former DIA chief’s foreign policy positions can be shaped by the highest bidder.

Flynn did not respond to a request for comment.

“It’s problematic,” Henri Barkey, the director of the Middle East program at the Woodrow Wilson International Center for Scholars, said. “Which Flynn are we dealing with? Is it the Flynn who got money lobbying for Turkey or is it the Flynn who is worried about what he calls ‘Islamic extremism’?”

James Jeffrey, a career diplomat who served as the U.S. ambassador to Turkey from 2008 to 2010, downplayed the significance of Flynn’s early support for the attempted coup.

“That was the initial response of many people … particularly those in the U.S. military who were angry at Erdogan for being lukewarm in the fight against ISIS,” Jeffrey said. “Flynn was just more open in talking about it.”

Once Gulen and his followers were accused of orchestrating the coup, Jeffrey said, “people changed their mind.”

But it’s not just Flynn’s contradictory statements that worry some Middle East analysts. It’s the fact that he spoke out in favor of a military takeover at all.

“I have serious concerns with Erdogan,” said Matt Duss, the president of the Foundation for Middle East Peace. “But the idea that a military coup would’ve solved these problems is a fantasy.”

In the same speech where he praised attempts to overthrow Turkey’s president, Flynn spoke admiringly of Abdel Fattah el-Sisi, the military general who led the 2013 coup in Egypt to overthrow Mohamed Morsi, the democratically elected Muslim Brotherhood member.

Since Sisi’s takeover, Duss said, “repression has gotten worse and it’s provided a huge boon to groups like al-Qaeda and ISIS who have been arguing that democracy is a dead end.”

Do you work in a federal agency? Email us at scoops@huffingtonpost.com a nd let us know what you’re seeing and hearing, and if you’re thinking of staying in government for the next administration.