// extract_json_helper — Go-side counterpart to the Rust
// parity_extract_json binary. Reads stdin, runs
// validator.ExtractJSON, prints {matched, value} JSON to stdout.
//
// Used exclusively by
// `scripts/cutover/parity/extract_json_parity.sh` to verify
// cross-runtime equivalence of extract_json across Rust and Go.
package main

import (
	"encoding/json"
	"fmt"
	"io"
	"os"

	"git.agentview.dev/profit/golangLAKEHOUSE/internal/validator"
)

func main() {
	buf, err := io.ReadAll(os.Stdin)
	if err != nil {
		fmt.Fprintf(os.Stderr, "read stdin: %v\n", err)
		os.Exit(1)
	}
	v := validator.ExtractJSON(string(buf))
	out := map[string]any{
		"matched": v != nil,
		"value":   v,
	}
	body, err := json.Marshal(out)
	if err != nil {
		fmt.Fprintf(os.Stderr, "marshal: %v\n", err)
		os.Exit(1)
	}
	fmt.Println(string(body))
}
