#pragma once

#include <optional>
#include <string>
#include <vector>

namespace fgc::paths {

// Expand a leading "~" (to $HOME) and any "$VAR" / "${VAR}" environment
// references in `path`. Returns the expanded path (unchanged if nothing to do).
std::string expandUser(const std::string& path);

// Absolute directory containing the running executable (via /proc/self/exe).
// Returns empty string if it cannot be determined.
std::string executableDir();

// The ordered list of locations searched for a config file, given an optional
// explicit --config argument. Exposed so callers can report what was tried.
std::vector<std::string> configSearchPaths(const std::string& cliArg = "");

// Resolve the config file path using configSearchPaths(): the first existing,
// readable file wins. Returns nullopt if none is found.
std::optional<std::string> resolveConfigPath(const std::string& cliArg = "");

// Default image output directory when none is configured
// ($XDG_DATA_HOME/fire_gimbal_control/images, else ~/.local/share/...).
std::string defaultOutputDir();

// Directory for diagnostic/calibration logfiles
// ($XDG_DATA_HOME/fire_gimbal_control/logs, else ~/.local/share/...).
std::string defaultLogDir();

// "<prefix>_YYYYMMDD-HHMMSS.log" using the local clock.
std::string timestampedLogName(const std::string& prefix);

// Write `text` to `defaultLogDir()/<name>`, creating the directory if needed.
// Returns the full path written, or "" on failure (and logs a warning).
std::string writeLogFile(const std::string& name, const std::string& text);

}  // namespace fgc::paths
