from flask import Blueprint, jsonify, request

from services.jdr_service import jdr_service

jdr_bp = Blueprint('jdr', __name__, url_prefix='/api/jdr')


@jdr_bp.route('/dimensions', methods=['GET'])
def get_dimensions():
    try:
        result = jdr_service.get_dimension_scores()
        return jsonify({'code': 200, 'message': 'success', 'data': result})
    except Exception as e:
        return jsonify({'code': 500, 'message': str(e), 'data': None}), 500


@jdr_bp.route('/burnout-engagement', methods=['GET'])
def get_burnout_engagement():
    try:
        result = jdr_service.get_burnout_engagement_analysis()
        return jsonify({'code': 200, 'message': 'success', 'data': result})
    except Exception as e:
        return jsonify({'code': 500, 'message': str(e), 'data': None}), 500


@jdr_bp.route('/path-analysis', methods=['GET'])
def get_path_analysis():
    try:
        result = jdr_service.get_jdr_path_analysis()
        return jsonify({'code': 200, 'message': 'success', 'data': result})
    except Exception as e:
        return jsonify({'code': 500, 'message': str(e), 'data': None}), 500


@jdr_bp.route('/profile', methods=['GET'])
def get_profile():
    try:
        dimension = request.args.get('dimension', '所属行业')
        result = jdr_service.get_jdr_profile(dimension)
        return jsonify({'code': 200, 'message': 'success', 'data': result})
    except Exception as e:
        return jsonify({'code': 500, 'message': str(e), 'data': None}), 500


@jdr_bp.route('/risk-distribution', methods=['GET'])
def get_risk_distribution():
    try:
        result = jdr_service.get_risk_distribution()
        return jsonify({'code': 200, 'message': 'success', 'data': result})
    except Exception as e:
        return jsonify({'code': 500, 'message': str(e), 'data': None}), 500
