package processor

import (
	"encoding/json"
	"fmt"

	"nms_nbi/src/framework/logger"
	"nms_nbi/src/framework/vo/result"
	neDataModel "nms_nbi/src/modules/network_data/model"
	neDataService "nms_nbi/src/modules/network_data/service"
)

// GetCDRConnect 获取CDR会话事件-IMS
func GetCDRConnect(requestID string, data any) ([]byte, error) {
	msgByte, _ := json.Marshal(data)
	var query neDataModel.CDREventQuery
	err := json.Unmarshal(msgByte, &query)
	if err != nil {
		logger.Warnf("ws processor GetCDRConnect err: %s", err.Error())
		return nil, fmt.Errorf("query data structure error")
	}

	dataMap := neDataService.NewCDREventImpl.SelectPage(query)
	resultByte, err := json.Marshal(result.Ok(map[string]any{
		"requestId": requestID,
		"data":      dataMap,
	}))
	return resultByte, err
}
