package sys_optionset

import (
	"context"
	"errors"
	"git.i2edu.net/i2/i2-bill-erp/transform"

	"git.i2edu.net/i2/i2-bill-api/internal/svc"
	"git.i2edu.net/i2/i2-bill-api/internal/types"

	"git.i2edu.net/i2/go-zero/core/logx"
)

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

func NewGetErpOptionsetLogic(ctx context.Context, svcCtx *svc.ServiceContext) GetErpOptionsetLogic {
	return GetErpOptionsetLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetErpOptionsetLogic) GetErpOptionset(req string) (*types.Response, error) {

	// todo: add your logic here and delete this line
	if req == "" {
		return nil, errors.New("请输入字典编码")
	}
	res, err := l.svcCtx.Transformer.GetErpOptionset(l.ctx, &transform.OptionCode{Code: req})
	var msg string
	var code = 200
	var data = res
	if err != nil {
		code = 500
		msg = err.Error()
		data = nil
	}
	return &types.Response{Code: code, Msg: msg, Data: data}, nil

}
