//go:build ignore
// +build ignore

package main

import (
	"embed"
	"entgo.io/ent/entc"
	"entgo.io/ent/entc/gen"
	"log"
)

//go:embed template
var EntTemplate embed.FS

func NewTemplate(patterns ...string) *gen.Template {
	return gen.MustParse(gen.NewTemplate("template").
		Funcs(gen.Funcs).
		ParseFS(EntTemplate, patterns...))
}

func main() {
	opts := []entc.Option{
		//entc.Dependency(
		//	entc.DependencyName("Data"),
		//	entc.DependencyType(&data.Data{}),
		//),
	}
	genConf := &gen.Config{
		Schema: "",
		Templates: []*gen.Template{
			NewTemplate(
				"template/builder/query.tmpl",
				"template/builder/create.tmpl",
				"template/builder/delete.tmpl",
				"template/builder/update.tmpl",
				"template/dialect/sql/query.tmpl",
				"template/dialect/sql/create.tmpl",
				"template/dialect/sql/delete.tmpl",
				"template/dialect/sql/update.tmpl",
				"template/meta.tmpl",
			),
		},
		// --feature intercept,sql/upsert,sql/modifier,sql/lock,sql/execquery ../schema
		Features: []gen.Feature{
			gen.FeatureIntercept,
			gen.FeatureUpsert,
			gen.FeatureModifier,
			gen.FeatureLock,
			gen.FeatureExecQuery,
		},
	}
	if err := entc.Generate("../schema", genConf, opts...); err != nil {
		log.Fatal("running ent codegen:", err)
	}
}
