// A command line tool for generating typescript type declarations from go
// struct types.
//
// Example:
//
//	go run ./cmd/go2ts -o webui/src/types.ts
package main

import (
	"flag"
	"fmt"
	"os"

	"go.skia.org/infra/go/go2ts"
	"sketch.dev/git_tools"
	"sketch.dev/llm"
	"sketch.dev/loop"
	"sketch.dev/loop/server"
)

func main() {
	outputPath := flag.String("o", "", "Path to the output TypeScript file.")
	flag.Parse()

	generator := TS()

	w, err := os.Create(*outputPath)
	if err != nil {
		fmt.Printf("error: %v\n", err)
		os.Exit(1)
	}
	fmt.Fprintf(w, "// Auto-generated by sketch.dev/cmd/go2ts.go\n")
	generator.Render(w)
}

// TS returns a Go2TS generator for go types we want to use in TypeScript.
func TS() *go2ts.Go2TS {
	generator := go2ts.New()

	// Enum types
	generator.AddMultipleUnion(
		[]loop.CodingAgentMessageType{
			loop.UserMessageType,
			loop.AgentMessageType,
			loop.ErrorMessageType,
			loop.BudgetMessageType,
			loop.ToolUseMessageType,
			loop.CommitMessageType,
			loop.AutoMessageType,
		},
	)

	// Struct types
	generator.AddMultiple(
		loop.AgentMessage{},
		loop.GitCommit{},
		loop.ToolCall{},
		llm.Usage{},
		server.State{},
		loop.MultipleChoiceOption{},
		loop.MultipleChoiceParams{},
		git_tools.DiffFile{},
		git_tools.GitLogEntry{},
	)

	generator.GenerateNominalTypes = true

	return generator
}
