package dictionary_admin

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

	"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 GetDictionaryAdminLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	r      *http.Request
}

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

func (l *GetDictionaryAdminLogic) GetDictionaryAdmin(req *types.DictionaryReq) (resp *types.DictionaryInfo, err error) {
	rpcResp, err := l.svcCtx.CoreRpc.GetDictionary(l.ctx, &core.DictionaryReq{
		ID:          req.ID,
		Name:        req.Name,
		Title:       req.Title,
		WithDetails: false,
		Page:        nil,
	})
	if err != nil {
		return nil, err
	}
	resp = l.svcCtx.Convert.ConvertDictionary(l.ctx, rpcResp)
	return
}
