// labcheck runs the project's own independent invariant checker against
// workflow IDs given on the command line. Copy this directory to
// cmd/labcheck inside the repository (it imports internal packages).
package main

import (
	"context"
	"fmt"
	"os"

	"durable-agent-execution-engine/internal/invariants"
	"durable-agent-execution-engine/internal/state"
)

func main() {
	ctx := context.Background()
	store, err := state.NewFromURL(ctx, os.Getenv("DATABASE_URL"))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	defer store.Close()
	for _, id := range os.Args[1:] {
		trace, err := invariants.Load(ctx, store, []string{id})
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			os.Exit(1)
		}
		verdict := invariants.Check(trace)
		fmt.Printf("%-10s valid=%v violations=%v\n", id, verdict.Valid, verdict.Violations)
	}
}
