Barcelona have agreed a purchase option with Gremio for Brazil midfielder Arthur Melo after talks took place in the Catalan city throughout the last week.

As part of the agreement, Barca say they have the right to sign Arthur in July for an upfront fee of €30 million plus an additional €9m in potential add-ons.

The two clubs have been in negotiations since December, when a photograph of Arthur with Barca's sporting director Robert Fernandez was leaked to the press.

"FC Barcelona and the Brazilian club Gremio de Porto Alegre have reached an agreement on a purchase option for the player Arthur Henrique Ramos de Oliveira Melo, whereas FC Barcelona may exercise this right on the player's federative rights during July of 2018," Barca said in a statement on Sunday.

"In the event that the club finally exercises the option signed, the price of the transfer is set at €30m plus €9m in variable amounts."

The payment type, the add-ons and the date of the transfer were the major stumbling blocks during the drawn-out negotiations.

Arthur has been described as a talented midfielder notable for his passing ability. Marcelo Endelli/Getty Images

Gremio had hoped to hang on to the player until next January, allowing him to complete another domestic season in Brazil.

However, Barca pushed for the deal to be done this summer, allowing Arthur to join the club for preseason and to give him more time to adapt to his new surroundings.

Barca have been following Arthur extensively since last year, when he helped Gremio win their first Copa Libertadores trophy since 1995.

The Catalan club say that Arthur, who is still just 21, is "a talented midfielder who stands out for his passing ability."

He has yet to be capped for his country but he has been included in recent squads and is hopeful of being called up by coach Tite for the World Cup this summer.

One potential problem Barca have if they exercise their right to sign him in July is freeing up a non-EU place.

Rules in Spain allow each club to only have three non-EU players, with Barcelona's spaces currently taken up by Yerry Mina, Paulinho and Philippe Coutinho.

The club are working on a way of helping Coutinho obtain an EU passport through his girlfriend, though.

Arthur, who has expressed his desire to move to Camp Nou throughout the last few months, will sign a five-year deal if Barca finalise the move in July.