package category

import (
	"context"
	"time"

	"bsm/full/module/base/cms/internal/models"
	pb "bsm/full/module/base/cms/pb"
	"git.apinb.com/bsm-sdk/core/errcode"
	"git.apinb.com/bsm-sdk/core/printer"
	"git.apinb.com/bsm-sdk/core/service"
)

// 删除分类
func Delete(ctx context.Context, in *pb.DeleteCategoryRequest) (reply *pb.StatusReply, err error) {
	_, err = service.ParseMetaCtx(ctx, nil)
	if err != nil {
		return nil, err
	}
	if in.GetIdentity() == "" || len(in.GetIdentity()) > 255 {
		return nil, errcode.ErrInvalidArgument
	}
	if err := models.DeleteCategory(in.GetIdentity()); err != nil {
		printer.Error(err.Error())
		return nil, err
	}
	return &pb.StatusReply{
		Code:    0,
		Message: "OK",
		Timeseq: time.Now().Unix(),
	}, nil

}
