from flask import Blueprint, request, jsonify
from models.integracao import calcular_cota

cota_bp = Blueprint('cota', __name__)

@cota_bp.route('/calculate_cota', methods=['POST'])
def calculate_cota():
    try:
        data = request.get_json()
        
        # Extrair dados do request
        salary = float(data.get('salary', 0))
        num_children = int(data.get('num_children', 0))
        pays_school = bool(data.get('pays_school', False))
        pays_rent = bool(data.get('pays_rent', False))
        num_parents = int(data.get('num_parents', 0))
        
        # Calcular a cota (implemente sua lógica de cálculo aqui)
        cota = calcular_cota(
            salary=salary,
            num_children=num_children,
            pays_school=pays_school,
            pays_rent=pays_rent,
            num_parents=num_parents
        )
        
        return jsonify({'cota': cota})
    
    except Exception as e:
        return jsonify({'error': str(e)}), 400 