package driverapp

import (
	"flag"
	"fmt"
	"log"
	"os"
	"path/filepath"

	"git.gocasts.ir/ebhomengo/niki/driverapp"
	cfgloader "git.gocasts.ir/ebhomengo/niki/pkg/cfg_loader"
	"git.gocasts.ir/ebhomengo/niki/pkg/migrator"
	"git.gocasts.ir/ebhomengo/niki/repository/mysql"
)

func main() {
	var cfg driverapp.Config

	workingDir, err := os.Getwd()
	if err != nil {
		fmt.Printf("Error getting current working directory: %v", err)
	}

	options := cfgloader.Option{
		Prefix:       "DRIVER_",
		Delimiter:    ".",
		Separator:    "__",
		YamlFilePath: filepath.Join(workingDir, "deploy", "driver", "development", "config.yaml"),
		CallbackEnv:  nil,
	}

	lErr := cfgloader.Load(options, &cfg)
	if lErr != nil {
		log.Fatalf("Failed to load driver config: %v", err)
	}

	conn := mysql.New(cfg.MysqlDB)

	mgr := migrator.New(cfg.MysqlDB, cfg.PathOfMigration)

	migrate := flag.Bool("migrate", false, "perform database migrations")
	flag.Parse()

	if *migrate {
		fmt.Println("Running migrations")
		mgr.Up()
	}

	//dapp := driverapp.Setup(cfg)
	//dapp.Start()

}
