// Package constants provides centralized path definitions for the RedFlag agent.
// This package ensures consistency across all components and makes path management
// maintainable and testable.
package constants

import (
	"path/filepath"
	"runtime"
)

// Base directories
const (
	LinuxBaseDir   = "/var/lib/redflag"
	WindowsBaseDir = "C:\\ProgramData\\RedFlag"
)

// Subdirectory structure
const (
	AgentDir        = "agent"
	ServerDir       = "server"
	CacheSubdir     = "cache"
	StateSubdir     = "state"
	MigrationSubdir = "migration_backups"
)

// Config paths
const (
	LinuxConfigBase   = "/etc/redflag"
	WindowsConfigBase = "C:\\ProgramData\\RedFlag"
	ConfigFile        = "config.json"
)

// Log paths
const (
	LinuxLogBase = "/var/log/redflag"
)

// Legacy paths for migration
const (
	LegacyConfigPath = "/etc/aggregator/config.json"
	LegacyStatePath  = "/var/lib/aggregator"
)

// GetBaseDir returns platform-specific base directory
func GetBaseDir() string {
	if runtime.GOOS == "windows" {
		return WindowsBaseDir
	}
	return LinuxBaseDir
}

// GetAgentStateDir returns /var/lib/redflag/agent/state
func GetAgentStateDir() string {
	return filepath.Join(GetBaseDir(), AgentDir, StateSubdir)
}

// GetAgentCacheDir returns /var/lib/redflag/agent/cache
func GetAgentCacheDir() string {
	return filepath.Join(GetBaseDir(), AgentDir, CacheSubdir)
}

// GetMigrationBackupDir returns /var/lib/redflag/agent/migration_backups
func GetMigrationBackupDir() string {
	return filepath.Join(GetBaseDir(), AgentDir, MigrationSubdir)
}

// GetAgentConfigPath returns /etc/redflag/agent/config.json
func GetAgentConfigPath() string {
	if runtime.GOOS == "windows" {
		return filepath.Join(WindowsConfigBase, AgentDir, ConfigFile)
	}
	return filepath.Join(LinuxConfigBase, AgentDir, ConfigFile)
}

// GetAgentConfigDir returns /etc/redflag/agent
func GetAgentConfigDir() string {
	if runtime.GOOS == "windows" {
		return filepath.Join(WindowsConfigBase, AgentDir)
	}
	return filepath.Join(LinuxConfigBase, AgentDir)
}

// GetServerPublicKeyPath returns /etc/redflag/server/server_public_key
func GetServerPublicKeyPath() string {
	if runtime.GOOS == "windows" {
		return filepath.Join(WindowsConfigBase, ServerDir, "server_public_key")
	}
	return filepath.Join(LinuxConfigBase, ServerDir, "server_public_key")
}

// GetAgentLogDir returns /var/log/redflag/agent
func GetAgentLogDir() string {
	return filepath.Join(LinuxLogBase, AgentDir)
}

// GetLegacyAgentConfigPath returns legacy /etc/aggregator/config.json
func GetLegacyAgentConfigPath() string {
	return LegacyConfigPath
}

// GetLegacyAgentStatePath returns legacy /var/lib/aggregator
func GetLegacyAgentStatePath() string {
	return LegacyStatePath
}
