A federal judge in California ruled this week that the Trump administration must stop separating migrant families and quickly reunite those already split.

Immigration advocates who had sued over the separation policy hailed the move, but experts cautioned that the ruling may not be straightforward to enforce. It's unclear how the various government agencies involved in separating families would work to reunite the roughly 2,000 children with their parents by the judge's 30-day deadline, lawyers and advocates said.

Here’s a look at what we know about the status of separated families and the potential moves to come.

What did the judge order?

U.S. District Court Judge Dana Sabraw issued a nationwide preliminary injunction Tuesday that stops the separation of migrant families and ordered the federal government to reunite already separated families. The judge ordered that families with children under 5 be reunited within 14 days, and families with older children within 30 days. Parents must also be allowed to speak with their children by telephone within 10 days.

The judge wrote that the government "has no system in place to keep track of, provide effective communication with, and promptly produce" migrant children.

“The unfortunate reality is that under the present system, migrant children are not accounted for with the same efficiency and accuracy as property,” Sabraw wrote, adding, "Certainly, that cannot satisfy the requirements of due process."

The judge’s ruling stems from a lawsuit filed by the ACLU on behalf of parents who were separated from their children after crossing the border, under Attorney General Jeff Sessions' “zero-tolerance” policy seeking to prosecute all adults who cross illegally.

Sabraw was critical of the administration's policy and said it had created its own crisis.

"The facts set forth before the court portray reactive governance — responses to address a chaotic circumstance of the government's own making," wrote Sabraw, a President George W. Bush appointee. "They belie measured and ordered governance, which is central to the concept of due process enshrined in our Constitution."

The judge also ordered that parents not be deported from the Unites States without their children.

What was the situation before the order?

The ruling followed President Donald Trump's executive order last week ending the separations. As of Tuesday, 2,047 children were still separated from their parents and in the custody of the Department of Health and Human Services, according to officials. That's only six fewer than the 2,053 separated children in HHS care as of June 20. An HHS official did not provide the ages of the children despite repeated requests during a Tuesday afternoon phone briefing.

Trump administration officials have repeatedly said that they know where all of the separated children are, but advocates and attorneys have described parents being unable to speak to or even locate their children for weeks after the separations.

Some parents and children have been reunited at Port Isabel Service Processing Center in Texas, according to the administration, but that’s only for families who are about to be deported.

Before Tuesday's ruling, a Trump official said parents who were in detention while fighting for asylum would not immediately be reunited with their children, who would remain in HHS custody. Parents who were released, such as into an ankle-monitor program, would be allowed to apply to sponsor their children, the official said.

Customs and Border Protection reunited more than 500 separated children over the past week, according to the administration, but those were children who had only recently been separated and had not yet been transferred to HHS.

On Tuesday night, an HHS spokesperson said the agency was still receiving children who were separated from their parents based on concern for the children's safety.

Can this work and what happens next?

The ACLU's leaders said the Trump administration is capable of reuniting families on the timeline set by the judge — if the administration makes it a priority.

“They have the resources they need to fix this crisis, if they have the political will,” Anthony Romero, the group's executive director, said during a media call Wednesday afternoon. “It’s a question of political will, not resources.”

Lee Gelernt, the lead lawyer in the case, added, “When the United States government puts all its resources to work, it can get something like this done easily.”

Some immigration attorneys, though, have expressed doubt at the administration's willingness or ability to reunite all of the families within the timeframe, noting the absence of a public, detailed process for reunification.

“It’s a quagmire on the policy level, on logistics and on ability,” said Muzaffar Chishti, director of the Migration Policy Institute’s office at New York University School of Law.

Morghan Richardson, an attorney and member of Lawyer Moms of America, a group formed in opposition to family separations, said the administration’s next steps were “completely not clear and that is really part of the problem.”

If the Trump administration fails to comply with the order, the ACLU's legal team will return to the judge and ensure the government is held accountable, Gelernt said.

What are the Trump administration’s options?

The Trump administration argued in a court filing Tuesday that the court should not grant the order because Trump had already issued the executive order ending the family separations.

The filing also said that agencies were already working to reunify families and said a court-imposed order would likely “slow the reunification process and cause confusion and conflicting obligations.”

Now, the Trump administration can either follow the order or attempt to stay the injunction and appeal to the 9th Circuit Court of Appeals, Chishti said. Gelernt said he had not heard as of Wednesday afternoon whether the administration would seek a stay of the injunction.

“If they appeal, it is still going to take some time," Richardson said. "In the meantime, it’s a victory to have these kids in some sort of process” for reunification, she added.

Asked on Wednesday if the administration would appeal, Trump said: "Well, we're going to see. But we believe that families should be together also. So there's not a lot to fight. But we believe families have to be together."

If the administration does appeal, and the 9th Circuit upholds the ruling, then the administration's final option would be to appeal directly to the Supreme Court. But the court just ended its regular session Wednesday, so the case would land in the hands of one justice — Justice Anthony Kennedy, who is assigned to the 9th Circuit.

On Wednesday afternoon, Kennedy announced he will retire at the end of next month.

Chishti said that because of his retirement, Kennedy may choose to consult the other justices and ask them to intervene on an emergency basis if the case were presented to him by July 31. After that, another justice would be placed in charge of cases from that circuit and could either decide the case or also choose to poll the other justices.

“Who that would be, we don’t know,” Chishti said.

Where will the reunited families go?

If the ruling stands and the Trump administration reunites the separated families, it's not yet clear where all those families would go.

Many of the separated parents are currently in detention facilities, where they could remain for months while waiting for their cases to be heard. Children, though, cannot stay in detention facilities for longer than 20 days under most circumstances, based on limits set in the 1997 Flores Settlement Agreement and subsequent court decisions.

The Justice Department has asked for that time limit to be extended so that families can remain together in detention while awaiting court appearances. The administration is also asking for an exemption from state licensing requirements for facilities holding families.

The case is now before Judge Dolly Gee in California, who previously set the 20-day limit for detaining children when President Barack Obama's administration tried to challenge the Flores Settlement.

If Gee denies the Justice Department's request, and if families must be reunited, then Trump would have no choice but to release the families under an ankle-monitor program or something similar, Chishti said.

“That is exactly counter to the Trump policy," he said, referring to zero tolerance. "That would be a complete defeat."