package invite

import (
	"context"
	"fmt"

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

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

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

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

func (l *GetMyInviteNetworkLogic) GetMyInviteNetwork() (resp *types.MyInviteNetworkData, err error) {
	uid, ok := middleware.UIDFrom(l.ctx)
	if !ok || uid <= 0 {
		return nil, fmt.Errorf("unauthorized")
	}
	net, err := l.svcCtx.Auth.GetMyNetwork(l.ctx, uid)
	if err != nil {
		return nil, err
	}
	return types.MyInviteNetworkFromUC(net), nil
}
