# -*- coding: utf-8 -*-
"""
도매상 설정 API

GET /api/config/wholesalers - 도매상 목록 (순서대로)
GET /api/config/wholesaler/<id> - 특정 도매상 정보
"""

from flask import Blueprint, jsonify
from config import get_wholesalers, get_wholesaler, get_config

wholesaler_config_bp = Blueprint('wholesaler_config', __name__, url_prefix='/api/config')


@wholesaler_config_bp.route('/wholesalers', methods=['GET'])
def api_get_wholesalers():
    """도매상 목록 반환"""
    wholesalers = get_wholesalers()
    return jsonify({
        'success': True,
        'wholesalers': wholesalers,
        'count': len(wholesalers)
    })


@wholesaler_config_bp.route('/wholesaler/<wholesaler_id>', methods=['GET'])
def api_get_wholesaler(wholesaler_id):
    """특정 도매상 정보 반환"""
    wholesaler = get_wholesaler(wholesaler_id)
    if wholesaler:
        return jsonify({
            'success': True,
            'wholesaler': wholesaler
        })
    else:
        return jsonify({
            'success': False,
            'error': 'NOT_FOUND',
            'message': f'도매상 {wholesaler_id}을(를) 찾을 수 없습니다'
        }), 404
