package menu

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"sundynix-micro-go/app/system/api/internal/svc"
	"sundynix-micro-go/app/system/api/internal/types"
	"sundynix-micro-go/app/system/rpc/system"
)

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

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

func (l *UpdateMenuLogic) UpdateMenu(req *types.MenuUpdateReq) error {
	_, err := l.svcCtx.SystemRpc.UpdateMenu(l.ctx, &system.MenuUpdateReq{
		Id: req.Id, ParentId: req.ParentId, Category: int32(req.Category), Name: req.Name, Title: req.Title,
		Code: req.Code, Path: req.Path, Permission: req.Permission, Locale: req.Locale,
		Icon: req.Icon, Sort: int32(req.Sort),
	})
	return err
}
