import * as plugins from './smartvpn.plugins.js';
/**
 * Install the smartvpn daemon as a system service.
 */
export class VpnInstaller {
    /**
     * Detect the current platform.
     */
    static detectPlatform() {
        switch (process.platform) {
            case 'linux':
                return 'linux';
            case 'darwin':
                return 'macos';
            case 'win32':
                return 'windows';
            default:
                return 'unknown';
        }
    }
    /**
     * Generate a systemd unit file for Linux.
     */
    static generateSystemdUnit(options) {
        const desc = options.description || `SmartVPN ${options.mode} daemon`;
        const content = `[Unit]
Description=${desc}
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
ExecStart=${options.binaryPath} --management-socket ${options.socketPath} --mode ${options.mode}
Restart=always
RestartSec=5
LimitNOFILE=65535

# Security hardening
NoNewPrivileges=no
ProtectSystem=strict
ProtectHome=yes
ReadWritePaths=/var/run /dev/net/tun
PrivateTmp=yes

[Install]
WantedBy=multi-user.target
`;
        return {
            platform: 'linux',
            content,
            installPath: `/etc/systemd/system/smartvpn-${options.mode}.service`,
        };
    }
    /**
     * Generate a launchd plist for macOS.
     */
    static generateLaunchdPlist(options) {
        const label = `rocks.push.smartvpn.${options.mode}`;
        const content = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>${label}</string>
  <key>ProgramArguments</key>
  <array>
    <string>${options.binaryPath}</string>
    <string>--management-socket</string>
    <string>${options.socketPath}</string>
    <string>--mode</string>
    <string>${options.mode}</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>KeepAlive</key>
  <true/>
  <key>StandardErrorPath</key>
  <string>/var/log/smartvpn-${options.mode}.err.log</string>
  <key>StandardOutPath</key>
  <string>/var/log/smartvpn-${options.mode}.out.log</string>
</dict>
</plist>
`;
        return {
            platform: 'macos',
            content,
            installPath: `/Library/LaunchDaemons/${label}.plist`,
        };
    }
    /**
     * Generate the appropriate service unit for the current platform.
     */
    static generateServiceUnit(options) {
        const platform = VpnInstaller.detectPlatform();
        switch (platform) {
            case 'linux':
                return VpnInstaller.generateSystemdUnit(options);
            case 'macos':
                return VpnInstaller.generateLaunchdPlist(options);
            default:
                throw new Error(`VpnInstaller: unsupported platform: ${platform}`);
        }
    }
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR2cG4uY2xhc3Nlcy52cG5pbnN0YWxsZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHZwbi5jbGFzc2VzLnZwbmluc3RhbGxlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssT0FBTyxNQUFNLHVCQUF1QixDQUFDO0FBR2pEOztHQUVHO0FBQ0gsTUFBTSxPQUFPLFlBQVk7SUFDdkI7O09BRUc7SUFDSSxNQUFNLENBQUMsY0FBYztRQUMxQixRQUFRLE9BQU8sQ0FBQyxRQUFRLEVBQUUsQ0FBQztZQUN6QixLQUFLLE9BQU87Z0JBQ1YsT0FBTyxPQUFPLENBQUM7WUFDakIsS0FBSyxRQUFRO2dCQUNYLE9BQU8sT0FBTyxDQUFDO1lBQ2pCLEtBQUssT0FBTztnQkFDVixPQUFPLFNBQVMsQ0FBQztZQUNuQjtnQkFDRSxPQUFPLFNBQVMsQ0FBQztRQUNyQixDQUFDO0lBQ0gsQ0FBQztJQUVEOztPQUVHO0lBQ0ksTUFBTSxDQUFDLG1CQUFtQixDQUFDLE9BTWpDO1FBQ0MsTUFBTSxJQUFJLEdBQUcsT0FBTyxDQUFDLFdBQVcsSUFBSSxZQUFZLE9BQU8sQ0FBQyxJQUFJLFNBQVMsQ0FBQztRQUN0RSxNQUFNLE9BQU8sR0FBRztjQUNOLElBQUk7Ozs7OztZQU1OLE9BQU8sQ0FBQyxVQUFVLHdCQUF3QixPQUFPLENBQUMsVUFBVSxXQUFXLE9BQU8sQ0FBQyxJQUFJOzs7Ozs7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