# Path: pynubank/utils/parsing.py
# def parse_pix_transaction(transaction: dict) -> dict:
#     if transaction['__typename'] != 'GenericFeedEvent':
#         return transaction
# 
#     if transaction['title'] in PIX_TRANSACTION_MAP.keys():
#         transaction['__typename'] = PIX_TRANSACTION_MAP[transaction['title']]
#         transaction['amount'] = parse_float(transaction['detail'])
# 
#     return transaction
# 
# def parse_float(value: str):
#     return float(re.search(r'(?:\d*\.)*\d+,\d{1,2}', value).group().replace('.', '').replace(',', '.'))


import pytest
from pynubank.utils.parsing import parse_pix_transaction, parse_float
def test_should_parse_reversal_pix_transaction():
    transaction = base_transaction.copy()
    transaction['title'] = 'Reembolso enviado'

    parsed = parse_pix_transaction(transaction)

    assert parsed['__typename'] == 'PixTransferOutReversalEvent'
    assert parsed['amount'] == 3668.40


def test_should_parse_failed_pix_transaction():
    transaction = base_transaction.copy()
    transaction['title'] = 'Transferência falhou'

    parsed = parse_pix_transaction(transaction)

    assert parsed['__typename'] == 'PixTransferFailedEvent'
    assert parsed['amount'] == 3668.40


@pytest.mark.parametrize(['test_value', 'expected'], [
    ('R$1,00', 1.0),
    ('R$0,01', 0.01),
    ('R$0,1', 0.1),
    ('R$1.000,20', 1000.20),
    ('R$83.120,11', 83120.11),
    ('R$9.183.120,11', 9183120.11),
    ('Projeção aproximada para 31 de Agosto de 2021, seu dinheiro renderá R$ 0,18', 0.18)
])
def test_parse_float(test_value: str, expected: float):

# Path: pynubank/utils/parsing.py
# def parse_pix_transaction(transaction: dict) -> dict:
#     if transaction['__typename'] != 'GenericFeedEvent':
#         return transaction
# 
#     if transaction['title'] in PIX_TRANSACTION_MAP.keys():
#         transaction['__typename'] = PIX_TRANSACTION_MAP[transaction['title']]
#         transaction['amount'] = parse_float(transaction['detail'])
# 
#     return transaction
# 
# def parse_float(value: str):
#     return float(re.search(r'(?:\d*\.)*\d+,\d{1,2}', value).group().replace('.', '').replace(',', '.'))


# Path: tests/test_parsing.py
import pytest
from pynubank.utils.parsing import parse_pix_transaction, parse_float

def test_should_parse_reversal_pix_transaction():
    transaction = base_transaction.copy()
    transaction['title'] = 'Reembolso enviado'

    parsed = parse_pix_transaction(transaction)

    assert parsed['__typename'] == 'PixTransferOutReversalEvent'
    assert parsed['amount'] == 3668.40


def test_should_parse_failed_pix_transaction():
    transaction = base_transaction.copy()
    transaction['title'] = 'Transferência falhou'

    parsed = parse_pix_transaction(transaction)

    assert parsed['__typename'] == 'PixTransferFailedEvent'
    assert parsed['amount'] == 3668.40


@pytest.mark.parametrize(['test_value', 'expected'], [
    ('R$1,00', 1.0),
    ('R$0,01', 0.01),
    ('R$0,1', 0.1),
    ('R$1.000,20', 1000.20),
    ('R$83.120,11', 83120.11),
    ('R$9.183.120,11', 9183120.11),
    ('Projeção aproximada para 31 de Agosto de 2021, seu dinheiro renderá R$ 0,18', 0.18)
])
def test_parse_float(test_value: str, expected: float):

    result = parse_float(test_value)