#include <iostream>
#include <cstdlib>
#include <ctime>

// 直接包含头文件中的算法
#include "src/gnb/rrc/measurement_logic.hpp"

int main() {
    std::srand(std::time(nullptr));
    
    std::cout << "=== RRC测量报告逻辑测试 ===" << std::endl;
    
    // 测试用例1：模拟测量数据生成
    std::cout << "\n1. 测量数据生成测试：" << std::endl;
    for (int ueId = 1; ueId <= 3; ueId++) {
        auto measurement = nr::gnb::measurement::HandoverDecisionEngine::generateSimulatedMeasurement(ueId);
        std::cout << "UE " << ueId << " 测量结果：" << std::endl;
        std::cout << "  服务小区 PCI=" << measurement.serving.pci 
                  << " RSRP=" << measurement.serving.rsrp << " dBm" << std::endl;
        std::cout << "  邻居小区 PCI=" << measurement.neighbors[0].pci 
                  << " RSRP=" << measurement.neighbors[0].rsrp << " dBm" << std::endl;
    }
    
    // 测试用例2：切换判决测试
    std::cout << "\n2. 切换判决测试：" << std::endl;
    
    // 创建需要切换的场景
    nr::gnb::measurement::UeMeasurementData testMeasurement;
    testMeasurement.ueId = 100;
    testMeasurement.serving.pci = 1;
    testMeasurement.serving.rsrp = -110;  // 弱信号
    testMeasurement.neighbors.resize(1);
    testMeasurement.neighbors[0].pci = 2;
    testMeasurement.neighbors[0].rsrp = -95; // 强信号，差值15dB > 8dB阈值
    
    int targetGnbId;
    bool shouldHandover = nr::gnb::measurement::HandoverDecisionEngine::shouldTriggerHandover(testMeasurement, targetGnbId);
    
    std::cout << "测试场景：服务小区RSRP=-110dBm，邻居小区RSRP=-95dBm" << std::endl;
    std::cout << "RSRP差值：" << (testMeasurement.neighbors[0].rsrp - testMeasurement.serving.rsrp) << " dB" << std::endl;
    std::cout << "切换决定：" << (shouldHandover ? "是" : "否") << std::endl;
    if (shouldHandover) {
        std::cout << "目标gNB ID：" << targetGnbId << std::endl;
    }
    
    // 测试用例3：不需要切换的场景
    testMeasurement.neighbors[0].rsrp = -108; // 差值只有2dB < 8dB阈值
    shouldHandover = nr::gnb::measurement::HandoverDecisionEngine::shouldTriggerHandover(testMeasurement, targetGnbId);
    
    std::cout << "\n测试场景：服务小区RSRP=-110dBm，邻居小区RSRP=-108dBm" << std::endl;
    std::cout << "RSRP差值：" << (testMeasurement.neighbors[0].rsrp - testMeasurement.serving.rsrp) << " dB" << std::endl;
    std::cout << "切换决定：" << (shouldHandover ? "是" : "否") << std::endl;
    
    // 测试用例4：PCI到gNB ID映射
    std::cout << "\n3. PCI到gNB ID映射测试：" << std::endl;
    for (int pci = 1; pci <= 5; pci++) {
        int gnbId = nr::gnb::measurement::HandoverDecisionEngine::mapPciToGnbId(pci);
        std::cout << "PCI " << pci << " -> gNB ID " << gnbId << std::endl;
    }
    
    std::cout << "\n=== 测试完成 ===" << std::endl;
    return 0;
}
