// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1

package wiki

import (
	"context"
	"fmt"

	"sundynix-micro-go/app/plant/api/internal/svc"
	"sundynix-micro-go/app/plant/api/internal/types"
	"sundynix-micro-go/app/plant/rpc/plant"

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

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

// 收藏/取消收藏百科
func NewToggleWikiStarLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ToggleWikiStarLogic {
	return &ToggleWikiStarLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ToggleWikiStarLogic) ToggleWikiStar(req *types.IdReq) error {
	userId := fmt.Sprintf("%v", l.ctx.Value("userId"))
	_, err := l.svcCtx.PlantRpc.ToggleWikiStar(l.ctx, &plant.ToggleStarReq{
		UserId:   userId,
		TargetId: req.Id,
		Type:     "wiki",
	})
	return err
}
