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 CreateMenuLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

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

func (l *CreateMenuLogic) CreateMenu(in *system.MenuReq) (*system.CommonResp, error) {
	menu := sysModel.SundynixMenu{
		ParentID: in.ParentId, Category: int(in.Category), Name: in.Name, Title: in.Title,
		Code: in.Code, Path: in.Path, Permission: in.Permission, Locale: in.Locale,
		Icon: in.Icon, Sort: int(in.Sort),
	}
	if err := l.svcCtx.DB.Create(&menu).Error; err != nil {
		return nil, fmt.Errorf("创建菜单失败")
	}
	return &system.CommonResp{Code: 200, Msg: "success"}, nil
}
