package tags

import (
	"context"
	"time"

	"bsm/full/module/base/cms/internal/impl"
	"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/service"
	"git.apinb.com/bsm-sdk/core/types"
)

// 修改标签
func Modify(ctx context.Context, in *pb.TagsItem) (reply *pb.StatusReply, err error) {
	_, err = service.ParseMetaCtx(ctx, nil)
	if err != nil {
		return nil, err
	}

	if in.GetTitle() == "" || in.GetCoverPath() == "" || in.GetIntro() == "" {
		return nil, errcode.ErrInvalidArgument
	}

	var tagsData = &models.CmsTags{
		Title:        in.Title,
		CoverPath:    in.CoverPath,
		Intro:        in.Intro,
		Std_Identity: types.Std_Identity{Identity: in.Identity},
	}

	// err = logic.ModifyTags(tagsData)

	if err := impl.DBService.Where("identity = ?", tagsData.Identity).Updates(tagsData).Error; err != nil {
		return nil, errcode.ErrDB
	}

	return &pb.StatusReply{
		Code:    0,
		Message: "OK",
		Timeseq: time.Now().Unix(),
	}, nil

}
