#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
应用配置管理
"""

import os

class Config:
    """基础配置"""
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'dev-secret-key-change-in-production'
    
    # 数据库配置
    DB_HOST = os.environ.get('DB_HOST', 'localhost')
    DB_PORT = int(os.environ.get('DB_PORT', '3306'))
    DB_USER = os.environ.get('DB_USER', 'callback_user')
    DB_PASSWORD = os.environ.get('DB_PASSWORD', 'dev_password_123')
    DB_NAME = os.environ.get('DB_NAME', 'callback_system')
    DB_CHARSET = os.environ.get('DB_CHARSET', 'utf8mb4')
    
    # SQLAlchemy 配置
    SQLALCHEMY_DATABASE_URI = f"mysql+pymysql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}?charset={DB_CHARSET}"
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLALCHEMY_ENGINE_OPTIONS = {
        'pool_pre_ping': True,
        'pool_recycle': 300,
    }

class DevelopmentConfig(Config):
    """开发环境配置"""
    DEBUG = True
    FLASK_ENV = 'development'

class ProductionConfig(Config):
    """生产环境配置"""
    DEBUG = False
    FLASK_ENV = 'production'

# 配置映射
config = {
    'development': DevelopmentConfig,
    'production': ProductionConfig,
    'default': DevelopmentConfig
}

# 门诊配置
CLINIC_CONFIG = {
    'clinic_xuexian': {'clinic_name': '学前街门诊'},
    'clinic_dafeng': {'clinic_name': '大丰门诊'},
    'clinic_dongting': {'clinic_name': '东亭门诊'},
    'clinic_helai': {'clinic_name': '河埒门诊'},
    'clinic_hongdou': {'clinic_name': '红豆门诊'},
    'clinic_huishan': {'clinic_name': '惠山门诊'},
    'clinic_mashan': {'clinic_name': '马山门诊'},
    'clinic_hospital': {'clinic_name': '通善口腔医院'},
    'clinic_xinwu': {'clinic_name': '新吴门诊'}
}

# 用户配置
DEFAULT_USERS = [
    # 学前街门诊 (3名用户)
    {'username': 'jinqin', 'password': 'jinqin123', 'role': 'clinic_user', 'clinic_id': 'clinic_xuexian', 'real_name': '金沁', 'clinic_name': '学前街门诊'},
    {'username': 'renshanshan', 'password': 'renshanshan123', 'role': 'clinic_user', 'clinic_id': 'clinic_xuexian', 'real_name': '任姗姗', 'clinic_name': '学前街门诊'},
    {'username': 'shaojun', 'password': 'shaojun123', 'role': 'clinic_user', 'clinic_id': 'clinic_xuexian', 'real_name': '邵军', 'clinic_name': '学前街门诊'},
    
    # 新吴门诊 (1名用户)
    {'username': 'litingting', 'password': 'litingting123', 'role': 'clinic_user', 'clinic_id': 'clinic_xinwu', 'real_name': '李婷婷', 'clinic_name': '新吴门诊'},
    
    # 红豆门诊 (2名用户)
    {'username': 'maqiuyi', 'password': 'maqiuyi123', 'role': 'clinic_user', 'clinic_id': 'clinic_hongdou', 'real_name': '马秋怡', 'clinic_name': '红豆门诊'},
    {'username': 'tangqimin', 'password': 'tangqimin123', 'role': 'clinic_user', 'clinic_id': 'clinic_hongdou', 'real_name': '汤其敏', 'clinic_name': '红豆门诊'},
    
    # 东亭门诊 (1名用户)
    {'username': 'yueling', 'password': 'yueling123', 'role': 'clinic_user', 'clinic_id': 'clinic_dongting', 'real_name': '岳玲', 'clinic_name': '东亭门诊'},
    
    # 马山门诊 (2名用户)
    {'username': 'jijunlin', 'password': 'jijunlin123', 'role': 'clinic_user', 'clinic_id': 'clinic_mashan', 'real_name': '季军林', 'clinic_name': '马山门诊'},
    {'username': 'zhouliping', 'password': 'zhouliping123', 'role': 'clinic_user', 'clinic_id': 'clinic_mashan', 'real_name': '周丽萍', 'clinic_name': '马山门诊'},
    
    # 通善口腔医院总院 (2名用户)
    {'username': 'feimiaomiao', 'password': 'feimiaomiao123', 'role': 'clinic_user', 'clinic_id': 'clinic_hospital', 'real_name': '费苗苗', 'clinic_name': '通善口腔医院'},
    {'username': 'chenxinyu', 'password': 'chenxinyu123', 'role': 'clinic_user', 'clinic_id': 'clinic_helai', 'real_name': '陈心语', 'clinic_name': '河埒门诊'},
    
    # 惠山门诊 (2名用户)
    {'username': 'yanghong', 'password': 'yanghong123', 'role': 'clinic_user', 'clinic_id': 'clinic_huishan', 'real_name': '杨红', 'clinic_name': '惠山门诊'},
    {'username': 'panjinli', 'password': 'panjinli123', 'role': 'clinic_user', 'clinic_id': 'clinic_huishan', 'real_name': '潘金丽', 'clinic_name': '惠山门诊'},
    
    # 大丰门诊 (1名用户)
    {'username': 'chenlin', 'password': 'chenlin123', 'role': 'clinic_user', 'clinic_id': 'clinic_dafeng', 'real_name': '陈琳', 'clinic_name': '大丰门诊'},
    
    # 总部管理员 (最高权限)
    {'username': 'admin', 'password': 'admin123', 'role': 'admin', 'clinic_id': None, 'real_name': '系统管理员', 'clinic_name': '总部管理'}
]

def get_user_by_username(username):
    """根据用户名获取用户信息"""
    for user in DEFAULT_USERS:
        if user['username'] == username:
            return user
    return None

def get_clinic_info(clinic_id):
    """根据clinic_id获取门诊信息"""
    return CLINIC_CONFIG.get(clinic_id, {'clinic_name': '未知门诊'})
