You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from typing import Any
|
|
|
|
from app.db.mock_database import SessionMockLocal
|
|
from app.db.mock_models import Customer
|
|
from app.services.domain.common import parse_float, stable_int
|
|
from app.services.orchestration.technical_normalizer import normalize_cpf
|
|
|
|
|
|
async def validar_cliente_venda(cpf: str, valor_veiculo: float) -> dict[str, Any]:
|
|
cpf_norm = normalize_cpf(cpf)
|
|
db = SessionMockLocal()
|
|
try:
|
|
cliente = db.query(Customer).filter(Customer.cpf == cpf_norm).first()
|
|
|
|
if cliente:
|
|
score = int(cliente.score)
|
|
limite = parse_float(cliente.limite_credito, 0.0)
|
|
restricao = bool(cliente.possui_restricao)
|
|
nome = cliente.nome
|
|
else:
|
|
entropy = stable_int(cpf_norm)
|
|
score = int(300 + (entropy % 550))
|
|
limite = float(30000 + (entropy % 150000))
|
|
restricao = entropy % 7 == 0
|
|
nome = "Cliente Simulado"
|
|
|
|
aprovado = (not restricao) and (valor_veiculo <= limite)
|
|
return {
|
|
"aprovado": aprovado,
|
|
"cpf": cpf_norm,
|
|
"nome": nome,
|
|
"score": score,
|
|
"limite_credito": limite,
|
|
"possui_restricao": restricao,
|
|
"valor_veiculo": valor_veiculo,
|
|
}
|
|
finally:
|
|
db.close()
|