import os from flask import Flask, jsonify, request app = Flask(__name__) VERSION = "v3" UNIT_PRICE = 12 BULK_MIN_QUANTITY = 10 BULK_DISCOUNT = 0.10 COMMIT = os.environ.get("APP_COMMIT", "development") BUILD = os.environ.get("APP_SEMVER", "development") def total_price(quantity): if quantity < 1 or quantity > 1000: raise ValueError("quantity must be between 1 and 1000") total = UNIT_PRICE * quantity if quantity >= BULK_MIN_QUANTITY: total = round(total * (1 - BULK_DISCOUNT), 2) return total @app.get("/") def index(): return jsonify(service="Startup Pricing", version=VERSION, build=BUILD, commit=COMMIT) @app.get("/health") def health(): return jsonify(status="ok", version=VERSION, build=BUILD) @app.get("/price") def price(): try: quantity = int(request.args.get("quantity", "1")) total = total_price(quantity) except ValueError as error: return jsonify(error=str(error)), 400 return jsonify(quantity=quantity, total=total, currency="USD")