from app.services.document_formatting import format_document_value, sentence_case_es, title_case_es


def test_person_name_uses_title_case():
    assert format_document_value("compareciente.1.nombreInformal", "pablo gonzalez valverde") == (
        "Pablo Gonzalez Valverde"
    )


def test_name_keeps_spanish_links_lowercase():
    assert title_case_es("maría de los ángeles pérez") == "María de los Ángeles Pérez"


def test_entity_and_territory_are_humanized():
    assert format_document_value("notaria.nombre", "3º NOTARIA DE COPIAPO") == "3º Notaria de Copiapo"
    assert format_document_value("notaria.comuna", "santiago centro") == "Santiago Centro"
    assert format_document_value("entidad.region", "REGIÓN DE ATACAMA") == "Región de Atacama"


def test_profession_and_generic_customer_values_start_uppercase():
    assert format_document_value(
        "compareciente.1.profesion", "ABOGADO", field_code="cliente_profesion", field_type="TEXTO"
    ) == "Abogado"
    assert format_document_value(
        "campo.observacion_cliente", "vive en el domicilio indicado", field_type="TEXTO"
    ) == "Vive en el domicilio indicado"


def test_identifiers_and_contacts_are_not_mutated():
    assert format_document_value("cliente.email", "Persona@Ejemplo.cl") == "Persona@Ejemplo.cl"
    assert format_document_value("cliente.rut", "12.345.678-5") == "12.345.678-5"
    assert format_document_value("cliente.telefono", "+56 9 1234 5678") == "+56 9 1234 5678"


def test_binary_or_url_markers_are_preserved():
    value = "base64:AbCdEf123"
    assert format_document_value("compareciente.1.firma", value) == value


def test_sentence_case_only_changes_the_leading_character():
    assert sentence_case_es("calle Los Carrera 123") == "Calle Los Carrera 123"
