// Package common
package constants

import (
	"os"
	"path/filepath"
)

// Constants for Size Constraints
const MinOSDSize = uint64(2147483648) // 2GB i.e. 2*1024*1024*1024

const (
	ClientConfigGlobalHostConst = "*"
	BootstrapPortConst          = 7443
)

// Time constants
const RgwRestartAgeThreshold = 2 // seconds

// string templates
const (
	LoopSpecId       = "loop,"
	DevicePathPrefix = "/dev/disk/by-id/"
	RgwSockPattern   = "client.radosgw.gateway"
	CliForcePrompt   = "If you understand the *RISK* and you're *ABSOLUTELY CERTAIN* that is what you want, pass --yes-i-really-mean-it."
)

// Path and filename constants

const (
	CephConfFileName         = "ceph.conf"
	CephAdminKeyringFileName = "ceph.keyring"
	V2OnlyMonIPPort          = ":3300"
	V2OnlyMonIPProtoPrefix   = "v2:"
)

// Misc
const (
	AdminKeyringFieldName = "keyring.client.admin"
	AdminKeyringTemplate  = "keyring.client.%s"
)

// Ceph Error Substrings
const RbdMirrorNonPrimaryPromoteErr = "image is primary within a remote cluster or demotion is not propagated yet"

type PathConst struct {
	ConfPath     string
	RunPath      string
	DataPath     string
	LogPath      string
	RootFs       string
	ProcPath     string
	SSLFilesPath string
	SnapPath     string
}

type PathFileMode map[string]os.FileMode

var GetPathConst = func() PathConst {
	return PathConst{
		ConfPath:     filepath.Join(os.Getenv("SNAP_DATA"), "conf"),
		RunPath:      filepath.Join(os.Getenv("SNAP_DATA"), "run"),
		DataPath:     filepath.Join(os.Getenv("SNAP_COMMON"), "data"),
		LogPath:      filepath.Join(os.Getenv("SNAP_COMMON"), "logs"),
		RootFs:       filepath.Join(os.Getenv("TEST_ROOT_PATH"), "/"),
		ProcPath:     filepath.Join(os.Getenv("TEST_ROOT_PATH"), "/proc"),
		SSLFilesPath: filepath.Join(os.Getenv("SNAP_COMMON"), "/"),
		SnapPath:     filepath.Join(os.Getenv("SNAP"), "/"),
	}
}

// File Modes
const (
	PermissionWorldNoAccess        = 0750
	PermissionOnlyUserAccess       = 0700
	PermissionUserRwWorldRAccess   = 0644
	PermissionUserRWGroupROWorldNA = 0640
)

func GetPathFileMode() PathFileMode {
	pathConsts := GetPathConst()
	return PathFileMode{
		pathConsts.ConfPath: PermissionWorldNoAccess,
		pathConsts.RunPath:  PermissionOnlyUserAccess,
		pathConsts.DataPath: PermissionOnlyUserAccess,
		pathConsts.LogPath:  PermissionOnlyUserAccess,
	}
}

// Regexes

// ClusterNameRegex is the regex for validating cluster names (a-z0-9)
const ClusterNameRegex = "^[a-z0-9]+$"

// Replication Events
const (
	EventEnableReplication    = "enable_replication"
	EventDisableReplication   = "disable_replication"
	EventListReplication      = "list_replication"
	EventStatusReplication    = "status_replication"
	EventConfigureReplication = "configure_replication"
)

// RbdJournalingEnableFeatureSet is a slice of features needed for journaling replication in RBD.
var RbdJournalingEnableFeatureSet = [...]string{"exclusive-lock", "journaling"}

const (
	EventPromoteReplication = "promote_replication"
	EventDemoteReplication  = "demote_replication"
)
