package logic

import (
	"context"
	"jyBXSubscribe/rpc/type/bxsubscribe"

	"jyBXSubscribe/api/internal/svc"
	"jyBXSubscribe/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetKeyLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetKeyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetKeyLogic {
	return &GetKeyLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetKeyLogic) GetKey(req *types.GetKeyReq) (resp *types.CommonResp, err error) {
	// todo: add your logic here and delete this line
	res, err := l.svcCtx.Suscribe.GetKey(l.ctx, &bxsubscribe.GetKeyReq{
		UserType:     req.UserType,
		UserId:       req.UserId,
		EntId:        req.EntId,
		EntUserId:    req.EntUserId,
		NewUserId:    req.NewUserId,
		IsEnt:        req.IsEnt,
		PowerSource:  req.PowerSource,
		UserPower:    req.UserPower,
		VipPower:     req.VipPower,
		MemberPower:  req.MemberPower,
		DeptId:       req.DeptId,
		PositionType: req.PositionType,
	})
	if err != nil {
		return &types.CommonResp{
			Err_code: res.ErrCode,
			Err_msg:  res.ErrMsg,
			Data:     nil,
		}, nil
	}
	return &types.CommonResp{
		Err_code: res.ErrCode,
		Err_msg:  res.ErrMsg,
		Data:     res,
	}, nil
}
