package configuration

import (
	"flag"
	"time"
)

var databaseLocationFlag *string

var forceCreateSchemaFlag *bool

var createSchemaFlag *bool

var serverHostFlag *string

var serverPortFlag *int

var recordsLimitFlag *int

var recordsOffsetFlag *int

// Write timeout in seconds
var writeTimeoutFlag *int

// Read timeout in seconds
var readTimeoutFlag *int

func Init() {
	databaseLocationFlag = flag.String("file", "SQLiteDatabase.db", "The file contains the sql lite database")

	forceCreateSchemaFlag = flag.Bool("force-new-schema", false, "Force create a new database by erasing the data. Overrides the new flag")

	createSchemaFlag = flag.Bool("new-schema", false, "Create a new database")

	serverHostFlag = flag.String("host", "localhost", "The host for the server")

	serverPortFlag = flag.Int("port", 8080, "The port for the server")

	recordsLimitFlag = flag.Int("limit", 10, "The number of records to return")

	recordsOffsetFlag = flag.Int("offset", 0, "The number of records to skip")

	writeTimeoutFlag = flag.Int("write-timeout", 10, "The write timeout in seconds")

	readTimeoutFlag = flag.Int("read-timeout", 10, "The read timeout in seconds")

	flag.Parse()
}

func GetForceCreateSchema() bool {
	return *forceCreateSchemaFlag
}

func GetCreateSchema() bool {
	return *createSchemaFlag
}

func GetWriteTimeout() time.Duration {
	result := time.Duration(*writeTimeoutFlag) * time.Second
	return result
}

func GetReadTimeout() time.Duration {
	result := time.Duration(*readTimeoutFlag) * time.Second
	return result
}

func GetServerHost() string {
	return *serverHostFlag
}

func GetRecordsOffset() int {
	return *recordsOffsetFlag
}

func GetRecordsLimit() int {
	return *recordsLimitFlag
}

func GetServerPort() int {
	return *serverPortFlag
}

func GetDatabaseLocation() string {
	return *databaseLocationFlag
}
