package cli

import (
	"iop/packages/go/config"
)

type persistentOutputFilter interface {
	Filter(chunk string) string
	Flush() string
	HasOutput() bool
	CompletionMessage() string
}

type passthroughOutputFilter struct {
	emitted bool
}

func (f *passthroughOutputFilter) Filter(chunk string) string {
	if chunk != "" {
		f.emitted = true
	}
	return chunk
}

func (f *passthroughOutputFilter) Flush() string {
	return ""
}

func (f *passthroughOutputFilter) HasOutput() bool {
	return f.emitted
}

func (f *passthroughOutputFilter) CompletionMessage() string {
	return ""
}

func newPersistentOutputFilter(target string, profile config.CLIProfileConf, prompt string, baselineAssistant string) persistentOutputFilter {
	if profile.Terminal && isClaudeTerminalProfile(target, profile) {
		return newClaudeTUIOutputFilter(prompt, baselineAssistant)
	}
	if profile.Terminal {
		return newTerminalPassthroughOutputFilter(prompt)
	}
	return &passthroughOutputFilter{}
}
