package member

import (
	"context"

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

// 获取群组成员列表
func Fetch(ctx context.Context, in *pb.IdentRequest) (reply *pb.GroupMemberReply, err error) {
	_, err = service.ParseMetaCtx(ctx, nil)
	if err != nil {
		return nil, err
	}

	if in.Identity == "" {
		return nil, errcode.ErrInvalidArgument
	}

	members, err := models.GetGroupMember(in.Identity)

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

	return &pb.GroupMemberReply{
		Total: int32(len(members)),
	}, nil
}
