# Pricing service: called only by front. No agent; we measure its coverage separately.
from flask import Flask, jsonify, request
from waitress import serve

app = Flask(__name__)

@app.post('/price')
def price():
    d = request.get_json(silent=True) or {}
    qty = d.get('qty', 0) if isinstance(d.get('qty'), int) else 0
    tier = d.get('tier', '')
    total = qty * 3
    if qty > 100:
        total = qty * 2                      # bulk discount
        if tier == 'wholesale':
            total = qty                      # wholesale price
            if qty % 7 == 0:
                raise RuntimeError('pricing table missing for this tier')   # the hidden bug
    return jsonify({'total': total})

serve(app, host='0.0.0.0', port=6000, threads=8)
