#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
簡化測試腳本
"""

import os
import sys
sys.path.append('.')

def test_basic_imports():
    """測試基本導入"""
    try:
        # 測試基本配置
        from app.config import Config
        print("Config imported successfully")
        
        # 測試資料庫連線 
        import pymysql
        connection = pymysql.connect(
            host='mysql.theaken.com',
            port=33306,
            user='A060',
            password='WLeSCi0yhtc7',
            database='db_A060',
            charset='utf8mb4'
        )
        print("✓ Database connection successful")
        connection.close()
        
        # 測試 LDAP 導入
        import ldap3
        print("✓ LDAP3 imported successfully")
        
        # 測試文件處理庫
        import docx
        print("✓ python-docx imported successfully")
        
        import requests
        print("✓ requests imported successfully")
        
        return True
        
    except Exception as e:
        print(f"✗ Basic import test failed: {e}")
        return False

def test_app_creation():
    """測試應用程式創建（不使用資料庫）"""
    try:
        from flask import Flask
        app = Flask(__name__)
        
        # 基本配置
        app.config['SECRET_KEY'] = 'test-key'
        app.config['TESTING'] = True
        
        print("✓ Flask app created successfully")
        
        @app.route('/health')
        def health():
            return {'status': 'ok'}
        
        # 測試應用程式是否可以正常創建
        with app.test_client() as client:
            response = client.get('/health')
            print(f"✓ Flask app test route works: {response.status_code}")
        
        return True
        
    except Exception as e:
        print(f"✗ Flask app creation failed: {e}")
        return False

if __name__ == '__main__':
    print("Running basic system tests...")
    
    print("\n1. Testing basic imports:")
    import_ok = test_basic_imports()
    
    print("\n2. Testing Flask app creation:")
    app_ok = test_app_creation()
    
    print("\n=== Test Summary ===")
    print(f"Basic imports: {'PASS' if import_ok else 'FAIL'}")
    print(f"Flask app creation: {'PASS' if app_ok else 'FAIL'}")
    
    if import_ok and app_ok:
        print("\n✓ Basic system requirements are satisfied")
    else:
        print("\n✗ System has issues that need to be resolved")