package main

import (
	"app/shelfly/internal/models"
	"log"
	"gorm.io/driver/sqlite"
	"gorm.io/gen"
	"gorm.io/gorm"
)

// Dynamic SQL
type Querier interface {
  // SELECT * FROM @@table WHERE name = @name{{if role !=""}} AND role = @role{{end}}
  FilterWithNameAndRole(name, role string) ([]gen.T, error)
}

func main() {
  g := gen.NewGenerator(gen.Config{
    OutPath: "../query",
    Mode: gen.WithoutContext|gen.WithDefaultQuery|gen.WithQueryInterface, // generate mode
  })
  dbName:="shelfly_db.db"

  db, err := gorm.Open(sqlite.Open(dbName), &gorm.Config{})

	if err != nil {
		log.Fatalf("Erreur de connexion à la base de données : %v", err)
	}
  g.UseDB(db) // reuse your gorm db

  // Generate basic type-safe DAO API for struct `model.User` following conventions
  g.ApplyBasic(models.User{},models.Files{})

  // Generate Type Safe API with Dynamic SQL defined on Querier interface for `model.User` and `model.Company`
  g.ApplyInterface(func(Querier){},models.User{},models.Files{},models.LibrarySection{},models.MediaItem{},models.MediaPart{},models.MetadataItem{},models.SectionLocation{},models.Tag{},models.Tagging{},models.PathDownload{})

  // Generate the code
  g.Execute()
}