package tag

import (
	"context"

	"git.apinb.com/bsm-sdk/core/errcode"
	"git.apinb.com/bsm-sdk/core/printer"
	"git.apinb.com/bsm-sdk/core/service"
	"git.apinb.com/bsm-sdk/core/utils"
	"bsm/full/module/social/feed/internal/models"
	pb "bsm/full/module/social/feed/pb"
)

// 新建标签
func Create(ctx context.Context, in *pb.AddTagRequest) (reply *pb.StatusReply, err error) {
	_, err = service.ParseMetaCtx(ctx, nil)
	if err != nil {
		return nil, err
	}
	if len(in.GetTags()) == 0 {
		return nil, errcode.ErrInvalidArgument
	}
	var tags = &[]models.FeedTags{}
	for _, val := range in.Tags {
		*tags = append(*tags, models.FeedTags{
			Key:     utils.UUID(),
			Content: val,
		})
	}
	if err := models.AddTags(tags); err != nil {
		printer.Error(err.Error())
		return nil, errcode.ErrDB
	}

	return &pb.StatusReply{}, nil

}
