package threads_account

import (
	"context"

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

type ListThreadsAccountsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewListThreadsAccountsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListThreadsAccountsLogic {
	return &ListThreadsAccountsLogic{ctx: ctx, svcCtx: svcCtx}
}

func (l *ListThreadsAccountsLogic) ListThreadsAccounts() (*types.ListThreadsAccountsData, error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	result, err := l.svcCtx.ThreadsAccount.List(l.ctx, tenantID, uid)
	if err != nil {
		return nil, err
	}
	return toListData(result), nil
}
