namespace MCPForUnity.Editor.Services.Server
{
///
/// Interface for managing PID files and handshake state for the local HTTP server.
/// Handles persistence of server process information across Unity domain reloads.
///
public interface IPidFileManager
{
///
/// Gets the directory where PID files are stored.
///
/// Path to the PID file directory
string GetPidDirectory();
///
/// Gets the path to the PID file for a specific port.
///
/// The port number
/// Full path to the PID file
string GetPidFilePath(int port);
///
/// Attempts to read the PID from a PID file.
///
/// Path to the PID file
/// Output: the process ID if found
/// True if a valid PID was read
bool TryReadPid(string pidFilePath, out int pid);
///
/// Attempts to extract the port number from a PID file path.
///
/// Path to the PID file
/// Output: the port number
/// True if the port was extracted successfully
bool TryGetPortFromPidFilePath(string pidFilePath, out int port);
///
/// Deletes a PID file.
///
/// Path to the PID file to delete
void DeletePidFile(string pidFilePath);
///
/// Stores the handshake information (PID file path and instance token) in EditorPrefs.
///
/// Path to the PID file
/// Unique instance token for the server
void StoreHandshake(string pidFilePath, string instanceToken);
///
/// Attempts to retrieve stored handshake information from EditorPrefs.
///
/// Output: stored PID file path
/// Output: stored instance token
/// True if valid handshake information was found
bool TryGetHandshake(out string pidFilePath, out string instanceToken);
///
/// Stores PID tracking information in EditorPrefs.
///
/// The process ID
/// The port number
/// Optional hash of the command arguments
void StoreTracking(int pid, int port, string argsHash = null);
///
/// Attempts to retrieve a stored PID for the expected port.
/// Validates that the stored information is still valid (within 6-hour window).
///
/// The expected port number
/// Output: the stored process ID
/// True if a valid stored PID was found
bool TryGetStoredPid(int expectedPort, out int pid);
///
/// Gets the stored args hash for the tracked server.
///
/// The stored args hash, or empty string if not found
string GetStoredArgsHash();
///
/// Clears all PID tracking information from EditorPrefs.
///
void ClearTracking();
///
/// Computes a short hash of the input string for fingerprinting.
///
/// The input string
/// A short hash string (16 hex characters)
string ComputeShortHash(string input);
}
}