package cast

import (
	"context"
	"fmt"
	"fonchain-fiee/api/accountFiee"
	"fonchain-fiee/cmd/config"
	"fonchain-fiee/pkg/model/login"
	"fonchain-fiee/pkg/service"

	"dubbo.apache.org/dubbo-go/v3/common/constant"
	"github.com/gin-gonic/gin"
)

func NewCtxWithUserInfo(ctx *gin.Context, customVals ...string) (newCtx context.Context) {
	var userInfo = login.Info{}
	if config.AppConfig.System.AppMode == "prod" || config.AppConfig.System.AppMode == "test" {
		//_, ok := ctx.Get("jwtInfo")
		if ctx == nil {
			userInfo = login.Info{
				ID:     0,
				Name:   "系统",
				TelNum: "",
			}
		} else {
			userInfo = login.GetUserInfoFromC(ctx)
		}
	} else {
		userInfo = login.Info{
			ID:     61,
			Name:   "小波",
			TelNum: "18288888888",
			SubNum: "FE00005",
		}
	}
	var mm = make(map[string]interface{}, 3)
	mm["userid"] = fmt.Sprintf("%d", userInfo.ID)
	mm["name"] = userInfo.Name
	mm["phone"] = userInfo.TelNum
	if len(customVals) > 0 {
		mm["name"] = customVals[0]
	}
	newCtx = context.WithValue(context.Background(), constant.DubboCtxKey("attachment"), mm)
	return
}

func GetArtistAccountInfo(artistID uint64) (*accountFiee.UserInfoResponse, error) {
	var infoResp *accountFiee.UserInfoResponse
	var err error
	if config.AppConfig.System.AppMode != "dev" {
		infoResp, err = service.AccountFieeProvider.Info(context.Background(), &accountFiee.InfoRequest{
			ID:     artistID,
			Domain: "app",
		})
		if err != nil {
			return nil, err
		}
	} else {
		infoResp = &accountFiee.UserInfoResponse{
			Id:     1234,
			Name:   "小波",
			TelNum: "18288888888",
			SubNum: "T12345",
		}
	}
	return infoResp, nil
}
