package logic

import (
	"context"
	"fmt"
	"github.com/zeromicro/go-zero/core/logx"
	sysModel "sundynix-micro-go/app/system/model"
	"sundynix-micro-go/app/system/rpc/internal/svc"
	"sundynix-micro-go/app/system/rpc/system"
)

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

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

func (l *CreateDictLogic) CreateDict(in *system.DictReq) (*system.CommonResp, error) {
	dict := sysModel.SundynixDict{Type: in.Type, Label: in.Label, Value: in.Value, Sort: int(in.Sort), Desc: in.Desc}
	if err := l.svcCtx.DB.Create(&dict).Error; err != nil {
		return nil, fmt.Errorf("创建字典失败")
	}
	return &system.CommonResp{Code: 200, Msg: "success"}, nil
}
