InDesign get count of text Frames vs count of Stories

My end goal is to determine if an InDesign document contains any threaded or linked text frames, and if so, alert the operator.

I initially thought I could easily accomplish this by comparing the count of text frames to the count of stories. For example, if the count of text frames is greater than the count of stories, the operator would receive an alert. However, I’ve found that text frames that are “pasted into” other frames are not detected as text frames with a simple call, such as:

tell application id "com.adobe.InDesign"
	set textFrameCount to count of text frames of document 1
	set storyCount to count of stories of document 1
	display dialog textFrameCount
	display dialog storyCount
end tell

However, after some more trial and error, I believe the logic used in the script below is rather sound:

set myIDList to {}
tell application id "com.adobe.InDesign"
	set api to all page items of document 1
	set textFrameCount to 0
	set storyCount to 0
	repeat with x in api
		if class of x is text frame then
			--do something to the rectangles
			set textFrameCount to textFrameCount + 1
			set myID to id of parent story of x
			--display dialog myID
			if myID is not in myIDList then
				set end of myIDList to myID
				set storyCount to storyCount + 1
			end if
		end if
	end repeat
end tell
--display dialog textFrameCount
---display dialog storyCount
if textFrameCount is greater than storyCount then
	display dialog "There are more text frames than there are stories, so most likely there are some threaded text frames."
end if

Thank you in advance!
-Jeff

As you have found, getting ‘text frames of document 1’ only gets those frames which are directly on the pages/spreads/pasteboard - not nested frames. Getting ‘all page items’ is the only way I know.
Your proposed script is sound but there is an alternative which does not require tracking stories.

tell application id "com.adobe.InDesign"
	set api to all page items of document 1
	repeat with x in api
		if class of x is text frame then
			if x's next text frame is not nothing then
				select x
				display dialog "The document contains threaded text frames."
				return
			else if x's text frames is not {} then
				select x
				display dialog "The document contains linked text frames."
				return
			end if
		end if
	end repeat
	display dialog "The document does not contain any threaded or linked text frames."
end tell

No need to point nested frames because they can’t be threaded.
Try this:

tell application id "InDn"
	count of (text frames of active document whose next text frame ≠ nothing)
end tell

Wow! Thank you both, very much! I will certainly utilize the “next text frame” logic instead of what I proposed, since it is much cleaner and simpler than my solution.

Thanks again,
-Jeff