package threads_account

import (
	"context"

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

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

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

func (l *ListThreadsOAuthLogsLogic) ListThreadsOAuthLogs() (*types.ListThreadsOAuthLogsData, error) {
	items := l.svcCtx.ThreadsAccount.ListOAuthDebugLogs(50)
	list := make([]types.ThreadsOAuthLogItem, 0, len(items))
	for _, item := range items {
		list = append(list, types.ThreadsOAuthLogItem{
			At:        item.At,
			Level:     item.Level,
			Stage:     item.Stage,
			AccountID: item.AccountID,
			Message:   item.Message,
		})
	}
	return &types.ListThreadsOAuthLogsData{List: list}, nil
}
