package generatedmarker

import (
	"bufio"
	"os"
	"strings"
)

// Text is the marker emitted near the head of generated source files.
const Text = "Generated by CLI Printing Press"

// HasInFile reports whether one of the file's first few lines contains Text.
func HasInFile(path string) bool {
	f, err := os.Open(path)
	if err != nil {
		return false
	}
	defer func() { _ = f.Close() }()

	scanner := bufio.NewScanner(f)
	scanner.Buffer(make([]byte, 4096), 64*1024)
	for line := 0; line < 5 && scanner.Scan(); line++ {
		if strings.Contains(scanner.Text(), Text) {
			return true
		}
	}
	return false
}
