package basic

import (
	"context"

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

// 获取群组列表
func Fetch(ctx context.Context, in *pb.Empty) (reply *pb.GroupsReply, err error) {
	auth, err := service.ParseMetaCtx(ctx, nil)
	if err != nil {
		return nil, err
	}

	groups, err := models.GetMyGroup(auth.ID)

	if err != nil {
		printer.Error(err.Error())
		return nil, errcode.ErrDB
	}

	return &pb.GroupsReply{
		Total: int32(len(groups)),
	}, nil
}
