package config

import (
	"fmt"

	"github.com/namsral/flag"
)

const (
	ChargeCallbackEndpoint = "chargecallback"
	ShortIdMinLength       = 8
	LongIdMinLength        = 32
)

var (
	Env,
	StoragePath,
	ApiPort,
	ApiInterface,
	ApiListen,
	ApiHost,
	SessionSecret,
	LnChargeApi,
	LnChargeToken,
	LndGrpcHost,
	LndGrpcPort,
	LndCertPath,
	LndAdminMacaroonPath,
	LockMacaroonIp,
	ShortIdSalt,

	HttpProxy,

	SqlDbHost,
	SqlDbUser,
	SqlDbPass string
)

func init() {
	// Storage
	flag.StringVar(&StoragePath, "bit4sat-storage-path", "file-storage", "base file storage path")

	// Api
	flag.StringVar(&ApiPort, "api-port", "8880", "api port number")
	flag.StringVar(&ApiInterface, "api-interface", "", "api listening interface")
	flag.StringVar(&ApiHost, "api-host", "", "reachable hostname for api (used by callbacks)")
	ApiListen = fmt.Sprintf("%s:%s", ApiInterface, ApiPort)

	flag.StringVar(&SessionSecret, "session-secret", "default-secret", "cookie sessions secret")

	// Database
	flag.StringVar(&SqlDbHost, "sql-db-host", "bit4sat", "sql db hostname")
	flag.StringVar(&SqlDbUser, "sql-db-user", "bit4sat", "sql db username")
	flag.StringVar(&SqlDbPass, "sql-db-pass", "bit4sat", "sql db pass")

	// LN Charge
	flag.StringVar(&LnChargeApi, "ln-charge-api", "", "ln charge api endpoint")
	flag.StringVar(&LnChargeToken, "ln-charge-token", "", "ln charge api token")

	// LND
	flag.StringVar(&LndGrpcHost, "lnd-grpc-host", "", "lnd host address")
	flag.StringVar(&LndGrpcPort, "lnd-grpc-port", "", "lnd port address")
	flag.StringVar(&LndCertPath, "lnd-cert-path", "", "lnd tls cert path")
	flag.StringVar(&LndAdminMacaroonPath, "lnd-macaroon-admin-path", "", "admin macaroon path")
	flag.StringVar(&LockMacaroonIp, "lock-macaroon-ip", "", "lock macaroon to ip address")

	flag.StringVar(&HttpProxy, "http-proxy", "", "http proxy for clients")

	flag.StringVar(&ShortIdSalt, "short-id-salt", "bit4sat-23591", "hashid salt")
	flag.StringVar(&Env, "env", "dev", "dev or prod")

	//log.Printf("locking macaroon to ip %s", LockMacaroonIp)

	flag.Parse()
}
