package detail

import (
	"context"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
	"github.com/jinzhu/copier"

	"git.noahlan.cn/n-admin/n-admin-server/api/internal/svc"
	"git.noahlan.cn/n-admin/n-admin-server/api/internal/types"

	"net/http"
)

type UpdateDictionaryDetailAdminLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	r      *http.Request
}

func NewUpdateDictionaryDetailAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *UpdateDictionaryDetailAdminLogic {
	return &UpdateDictionaryDetailAdminLogic{
		r:      r,
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateDictionaryDetailAdminLogic) UpdateDictionaryDetailAdmin(req *types.DictionaryDetailInfo) error {
	var rpcReq core.DictionaryDetailInfo
	_ = copier.Copy(&rpcReq, req)

	_, err := l.svcCtx.CoreRpc.UpdateDictionaryDetail(l.ctx, &rpcReq)
	if err != nil {
		return err
	}

	return nil
}
