package admin

import (
	"context"
	"strconv"

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

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

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

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

func (l *ListMemberIdentitiesLogic) ListMemberIdentities(req *types.AdminUidPath) (resp *types.AdminMemberIdentitiesData, err error) {
	uid, err := strconv.ParseInt(req.Uid, 10, 64)
	if err != nil {
		return nil, err
	}
	ids, err := l.svcCtx.Auth.ListIdentities(l.ctx, uid)
	if err != nil {
		return nil, err
	}
	list := make([]types.IdentityPublic, 0, len(ids))
	for _, id := range ids {
		list = append(list, types.IdentityFromModel(id))
	}
	return &types.AdminMemberIdentitiesData{List: list}, nil
}
