package basic

import (
	"context"
	"time"

	"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"
	"git.apinb.com/bsm-sdk/core/vars"
	"bsm/full/module/social/group/internal/impl"
	"bsm/full/module/social/group/internal/models"
	pb "bsm/full/module/social/group/pb"
)

// 修改群组信息
func Modify(ctx context.Context, in *pb.GroupItem) (reply *pb.StatusReply, err error) {
	auth, err := service.ParseMetaCtx(ctx, nil)
	if err != nil {
		return nil, err
	}

	record := &models.GroupBasic{
		Name:                 in.GetName(),
		Introduce:            in.GetIntroduce(),
		Avatar:               in.GetAvatar(),
		Background:           in.GetBackground(),
		Notice:               in.GetNotice(),
		EnableSearchByNumber: in.GetEnableSearchByNumber(),
		EnableSearchByName:   in.GetEnableSearchByName(),
	}
	record.Identity = utils.UUID()

	err = impl.DBService.Where("identity=? and creator_id=?", in.Identity, auth.ID).UpdateColumns(record).Error
	if err != nil {
		printer.Error(err.Error())
		return nil, errcode.ErrDB
	}

	return &pb.StatusReply{
		Data:    vars.OK,
		Timeseq: time.Now().UnixMilli(),
	}, nil

}
