// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1

package member

import (
	"context"

	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"

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

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

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

func (l *GetMemberCapabilitiesLogic) GetMemberCapabilities() (*types.MemberCapabilitiesData, error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	research, err := l.svcCtx.Placement.ResearchSettings(l.ctx, tenantID, uid)
	if err != nil {
		return nil, err
	}
	caps, err := l.svcCtx.ThreadsAccount.ResolveMemberCapabilities(l.ctx, tenantID, uid, research)
	if err != nil {
		return nil, err
	}
	return &types.MemberCapabilitiesData{
		DiscoverReady:          caps.DiscoverReady,
		AiReady:                caps.AiReady,
		PublishReady:           caps.PublishReady,
		DiscoverHint:           caps.DiscoverHint,
		AiHint:                 caps.AiHint,
		PublishHint:            caps.PublishHint,
		ActiveThreadsAccountId: caps.ActiveThreadsAccount,
	}, nil
}
