/*

 Copyright (c) [2023] [pcm]
 [pcm-coordinator] is licensed under Mulan PSL v2.
 You can use this software according to the terms and conditions of the Mulan PSL v2.
 You may obtain a copy of Mulan PSL v2 at:
          http://license.coscl.org.cn/MulanPSL2
 THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 See the Mulan PSL v2 for more details.

*/

package result

import (
	"context"
	"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
)

type ResponseSuccessBean struct {
	Code    uint32      `json:"code"`
	Msg     string      `json:"msg"`
	Data    interface{} `json:"data"`
	TraceID string      `json:"traceId,omitempty"`
}
type NullJson struct{}

func Success(data interface{}, ctx context.Context) *ResponseSuccessBean {
	resp := ResponseSuccessBean{}
	utils.Convert(data, resp)
	traceID := traceIDFromContext(ctx)
	return &ResponseSuccessBean{200, "OK", data, traceID}
}

type ResponseErrorBean struct {
	Code    uint32 `json:"code"`
	Msg     string `json:"msg"`
	TraceID string `json:"traceId,omitempty"`
}

func Error(errCode uint32, errMsg string, ctx context.Context) *ResponseErrorBean {
	traceID := traceIDFromContext(ctx)
	return &ResponseErrorBean{errCode, errMsg, traceID}
}
