package user

import (
	"context"
	"fmt"
	"time"

	"git.i2edu.net/i2/i2-bill-api/internal/svc"
	"git.i2edu.net/i2/i2-bill-api/internal/types"

	"git.i2edu.net/i2/go-zero/core/logx"
)

type JzQrCodeLogic struct {
	logx.Logger
	ctx        context.Context
	svcCtx     *svc.ServiceContext
	UserId     int64
	SessionKey string
}

func NewJzQrCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) JzQrCodeLogic {
	return JzQrCodeLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// JzQrCode 兼职人员兼职码
func (l *JzQrCodeLogic) JzQrCode() (*types.JzQrcodeResponse, error) {
	uid, err := l.svcCtx.Wechat.GenUserQrId(svc.QrcodeJzPrefix, l.UserId, map[string]interface{}{
		"userId":    l.UserId,
		"timestamp": time.Now().Unix(),
		"type":      "JzQrCode",
	})
	fmt.Println("--uid=", uid)
	// l.svcCtx.Wechat.GetQrParams(qrcodeJzPrefix, uid, map[string]interface{}{})
	if err != nil {
		return nil, err
	}
	uri, err := l.svcCtx.Wechat.GenQrCode(uid, "/pages/code/code")
	return &types.JzQrcodeResponse{
		FileId: uri,
	}, err
}
