//go:build ignore

package main

import (
	"crypto/sha256"
	"encoding/hex"
	"log"
	"os"
	"text/template"
)

const OutputPath = "bin_hash.go"
const Template = `// Code generated by go generate; DO NOT EDIT.
package bin

const WorkerHash = "{{.Hash}}"
`

func main() {
	data, err := os.ReadFile("worker")
	if err != nil {
		log.Fatalf("Failed to read worker file: %v", err)
	}

	hashBytes := sha256.Sum256(data)
	hashString := hex.EncodeToString(hashBytes[:])

	f, err := os.Create(OutputPath)
	if err != nil {
		log.Fatalf("Failed to create output file: %v", err)
	}
	defer f.Close()

	t := template.Must(template.New("hash").Parse(Template))
	err = t.Execute(f, struct{ Hash string }{Hash: hashString})
	if err != nil {
		log.Fatalf("Failed to execute template: %v", err)
	}

	log.Printf("Successfully generated %s, WorkerHash: %s", OutputPath, hashString)
}
