package dict

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 UpdateDictLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

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

func (l *UpdateDictLogic) UpdateDict(req *types.DictUpdateReq) error {
	_, err := l.svcCtx.SystemRpc.UpdateDict(l.ctx, &system.DictUpdateReq{
		Id: req.Id, Type: req.Type, Label: req.Label, Value: req.Value, Sort: int32(req.Sort), Desc: req.Desc,
	})
	return err
}
