package processor

import (
	"encoding/json"
	"fmt"

	"be.ems/src/framework/logger"
	"be.ems/src/framework/vo/result"
	neDataModel "be.ems/src/modules/network_data/model"
	neDataService "be.ems/src/modules/network_data/service"
)

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

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

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

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