from flask import Blueprint, request, jsonify
from config import db
from models.ai import AITokenPackage
from utils.decorators import token_required

token_bp = Blueprint('token_routes', __name__, url_prefix='/api/tokens')

@token_bp.route('/packages', methods=['GET', 'OPTIONS'])
def get_token_packages():
    """Get all token packages"""
    if request.method == 'OPTIONS':
        return '', 200
    try:
        packages = AITokenPackage.query.order_by(AITokenPackage.display_order.asc()).all()
        return jsonify({
            'packages': [pkg.to_dict() for pkg in packages]
        }), 200
    except Exception as e:
        return jsonify({'error': str(e)}), 500
