package options

import (
	"encoding/json"
	"esperframework/cliFlags"
)

type CLIFlagOptions struct {
	Config    string `json:"config"`
	Name      string `json:"name"`
	Port      int    `json:"port"`
	Watch     bool   `json:"watch"`
	ModuleDev bool   `json:"moduleDev"`
}

type Options struct {
	Name            string `json:"Name"`
	Root            string `json:"root"`
	Port            int    `json:"port"`
	Ext             string `json:"ext"`
	AppDir          string `json:"appDir"`
	AppPath         string `json:"appPath"`
	OutDir          string `json:"outDir"`
	OutPath         string `json:"outPath"`
	PublicPath      string `json:"publicPath"`
	CachePath       string `json:"cachePath"`
	CacheClientPath string `json:"cacheClientPath"`
	DepGraphPath    string `json:"depGraphPath"`
	Dev             bool   `json:"dev"`
	ModuleDev       bool   `json:"moduleDev"`
}

type ActionMeta struct {
	Action     string
	Message    string
	ActionPath string
	Ext        string
}

func Get() *Options {

	// Read Config from Go
	// GetOptionsFromConfig()

	flags := cliFlags.GetFlags()

	var options Options
	json.Unmarshal([]byte(*flags.Options), &options)
	return &options
}

func GetActionMeta() *ActionMeta {
	flags := cliFlags.GetFlags()

	var actionMeta ActionMeta
	json.Unmarshal([]byte(*flags.ActionMeta), &actionMeta)
	return &actionMeta
}

// func GetOptionsFromConfig() *Options {
// 	root := strings.Replace(os.Args[3], "--root=", "", 1)

// 	opts := GetDefaultExport(filepath.Join(root, "esperframework.config.js"), "esperframework.config.js")

// 	fmt.Printf("%+v\n", opts)

// 	fmt.Printf("%+v\n", os.Args)

// 	// var options Options
// 	// json.Unmarshal([]byte(opts), &options)

// 	// srcDir := "src/app"
// 	// if options.SrcDir != "" {
// 	// 	srcDir = options.SrcDir
// 	// }

// 	// srcPath := filepath.Join(root, srcDir)

// 	// outDir := "build"
// 	// if options.OutDir != "" {
// 	// 	outDir = options.OutDir
// 	// }

// 	// outPath := filepath.Join(root, outDir)

// 	// cachePath := filepath.Join(outPath, "cache")
// 	// strSplit := strings.Split(srcDir, "src/")
// 	// appDir := strings.Join(strSplit[1:], string(os.PathSeparator))
// 	// cacheAppPath := filepath.Join(outPath, "cache", appDir)

// 	// // dev := false
// 	// // if options.Dev {
// 	// // 	dev = options.Dev
// 	// // }

// 	// publicPath := "src/public"
// 	// if options.Public != "" {
// 	// 	publicPath = options.Public
// 	// }

// 	// stylesPath := "src/styles"
// 	// if options.Styles != "" {
// 	// 	stylesPath = options.Styles
// 	// }

// 	// options = Options{
// 	// 	Root:         root,
// 	// 	SrcDir:       srcDir,
// 	// 	SrcPath:      srcPath,
// 	// 	OutDir:       outDir,
// 	// 	OutPath:      outPath,
// 	// 	CachePath:    cachePath,
// 	// 	CacheAppPath: cacheAppPath,
// 	// 	Dev:          true, // default for testing
// 	// 	ModuleDev:    true, // default for testing
// 	// 	Public:       publicPath,
// 	// 	Styles:       stylesPath,
// 	// }

// 	return &Options{}
// }
