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

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

func (l *CreateDictionaryDetailAdminLogic) CreateDictionaryDetailAdmin(req *types.DictionaryDetailInfo) (resp *types.BaseID, err error) {
	var rpcReq core.DictionaryDetailInfo
	_ = copier.Copy(&rpcReq, req)

	rpcResp, err := l.svcCtx.CoreRpc.CreateDictionaryDetail(l.ctx, &rpcReq)
	if err != nil {
		return nil, err
	}
	resp = &types.BaseID{ID: rpcResp.ID}
	return

	return
}
