package invite

import (
	"context"

	"apps/backend/internal/svc"
	"apps/backend/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListInviteParentCandidatesLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewListInviteParentCandidatesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListInviteParentCandidatesLogic {
	return &ListInviteParentCandidatesLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
}

func (l *ListInviteParentCandidatesLogic) ListInviteParentCandidates(req *types.ListParentCandidatesReq) (resp *types.InviteParentCandidatesData, err error) {
	list, err := l.svcCtx.Auth.ListParentCandidates(l.ctx, req.ExcludeSubtreeRootUid)
	if err != nil {
		return nil, err
	}
	out := make([]types.InviteMemberBrief, 0, len(list))
	for _, b := range list {
		out = append(out, types.InviteBriefFromUC(b))
	}
	return &types.InviteParentCandidatesData{List: out}, nil
}
