export const runtimeConfigDefaults = {
    automation: {
        enabled: false,
        maxConcurrentRuns: 4,
        runHistoryLimit: 100,
        defaultTimeoutMs: 15 * 60 * 1000,
        catchUpWindowMinutes: 30,
        failureCooldownMs: 5 * 60 * 1000,
        deleteAfterRun: false,
    },
    controlPlane: {
        enabled: false,
        hostMode: 'local',
        host: '127.0.0.1',
        port: 3421,
        baseUrl: 'http://127.0.0.1:3421',
        streamMode: 'sse',
        allowRemote: false,
        trustProxy: false,
        tls: {
            mode: 'off',
            certFile: '',
            keyFile: '',
        },
    },
    httpListener: {
        hostMode: 'local',
        host: '127.0.0.1',
        port: 3422,
        trustProxy: false,
        tls: {
            mode: 'off',
            certFile: '',
            keyFile: '',
        },
    },
    web: {
        enabled: false,
        hostMode: 'local',
        host: '127.0.0.1',
        port: 3423,
        publicBaseUrl: 'http://127.0.0.1:3423',
        staticAssetsDir: 'dist/web',
    },
    watchers: {
        enabled: false,
        pollIntervalMs: 60_000,
        heartbeatIntervalMs: 15_000,
        recoveryWindowMinutes: 10,
    },
    service: {
        enabled: false,
        autostart: false,
        restartOnFailure: true,
        platform: 'auto',
        serviceName: 'goodvibes',
        logPath: '',
    },
    network: {
        outboundTls: {
            mode: 'bundled',
            customCaFile: '',
            customCaDir: '',
            allowInsecureLocalhost: false,
        },
        remoteFetch: {
            allowPrivateHosts: false,
        },
    },
};
export const runtimePrimaryConfigSettings = [
    {
        key: 'automation.enabled',
        type: 'boolean',
        default: false,
        description: 'Enable the automation subsystem',
    },
    {
        key: 'automation.maxConcurrentRuns',
        type: 'number',
        default: 4,
        description: 'Maximum automation runs that may execute concurrently',
        validate: (v) => typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 64,
    },
    {
        key: 'automation.runHistoryLimit',
        type: 'number',
        default: 100,
        description: 'Maximum run history entries retained per automation job',
        validate: (v) => typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 5000,
    },
    {
        key: 'automation.defaultTimeoutMs',
        type: 'number',
        default: 15 * 60 * 1000,
        description: 'Default execution timeout for automation runs in milliseconds',
        validate: (v) => typeof v === 'number' && Number.isInteger(v) && v >= 1_000 && v <= 24 * 60 * 60 * 1000,
    },
    {
        key: 'automation.catchUpWindowMinutes',
        type: 'number',
        default: 30,
        description: 'How long after startup the engine should catch up missed runs',
        validate: (v) => typeof v === 'number' && Number.isInteger(v) && v >= 0 && v <= 24 * 60,
    },
    {
        key: 'automation.failureCooldownMs',
        type: 'number',
        default: 5 * 60 * 1000,
        description: 'Cooldown applied after a failed automation run before retrying',
        validate: (v) => typeof v === 'number' && Number.isInteger(v) && v >= 0 && v <= 24 * 60 * 60 * 1000,
    },
    {
        key: 'automation.deleteAfterRun',
        type: 'boolean',
        default: false,
        description: 'Delete one-shot automation jobs after their first successful run',
    },
    {
        key: 'controlPlane.enabled',
        type: 'boolean',
        default: false,
        description: 'Enable the shared gateway/control-plane service',
    },
    {
        key: 'controlPlane.hostMode',
        type: 'enum',
        default: 'local',
        description: 'Network binding mode: local (127.0.0.1, default port), network (0.0.0.0, default port), custom (editable host and port)',
        enumValues: ['local', 'network', 'custom'],
    },
    {
        key: 'controlPlane.host',
        type: 'string',
        default: '127.0.0.1',
        description: 'Bind host for the control-plane HTTP server',
    },
    {
        key: 'controlPlane.port',
        type: 'number',
        default: 3421,
        description: 'Bind port for the control-plane HTTP server',
        validate: (v) => typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 65535,
    },
    {
        key: 'controlPlane.baseUrl',
        type: 'string',
        default: 'http://127.0.0.1:3421',
        description: 'Public base URL used by route bindings and link generation',
    },
    {
        key: 'controlPlane.streamMode',
        type: 'enum',
        default: 'sse',
        description: 'Live update stream mode for control-plane clients',
        enumValues: ['sse', 'websocket', 'both'],
    },
    {
        key: 'controlPlane.allowRemote',
        type: 'boolean',
        default: false,
        description: 'Allow remote clients to connect to the control plane',
    },
    {
        key: 'controlPlane.trustProxy',
        type: 'boolean',
        default: false,
        description: 'Trust proxy forwarding headers such as x-forwarded-for for the control plane',
    },
    {
        key: 'controlPlane.tls.mode',
        type: 'enum',
        default: 'off',
        description: 'TLS mode for the control-plane HTTP server',
        enumValues: ['off', 'proxy', 'direct'],
    },
    {
        key: 'controlPlane.tls.certFile',
        type: 'string',
        default: '',
        description: 'Certificate chain PEM path for direct control-plane TLS (empty = ~/.goodvibes/certs/fullchain.pem)',
    },
    {
        key: 'controlPlane.tls.keyFile',
        type: 'string',
        default: '',
        description: 'Private key PEM path for direct control-plane TLS (empty = ~/.goodvibes/certs/privkey.pem)',
    },
    {
        key: 'httpListener.hostMode',
        type: 'enum',
        default: 'local',
        description: 'Network binding mode: local (127.0.0.1, default port), network (0.0.0.0, default port), custom (editable host and port)',
        enumValues: ['local', 'network', 'custom'],
    },
    {
        key: 'httpListener.host',
        type: 'string',
        default: '127.0.0.1',
        description: 'Bind host for the webhook HTTP listener',
    },
    {
        key: 'httpListener.port',
        type: 'number',
        default: 3422,
        description: 'Bind port for the webhook HTTP listener',
        validate: (v) => typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 65535,
    },
    {
        key: 'httpListener.trustProxy',
        type: 'boolean',
        default: false,
        description: 'Trust proxy forwarding headers such as x-forwarded-for for the webhook listener',
    },
    {
        key: 'httpListener.tls.mode',
        type: 'enum',
        default: 'off',
        description: 'TLS mode for the webhook HTTP listener',
        enumValues: ['off', 'proxy', 'direct'],
    },
    {
        key: 'httpListener.tls.certFile',
        type: 'string',
        default: '',
        description: 'Certificate chain PEM path for direct webhook-listener TLS (empty = ~/.goodvibes/certs/fullchain.pem)',
    },
    {
        key: 'httpListener.tls.keyFile',
        type: 'string',
        default: '',
        description: 'Private key PEM path for direct webhook-listener TLS (empty = ~/.goodvibes/certs/privkey.pem)',
    },
    {
        key: 'web.enabled',
        type: 'boolean',
        default: false,
        description: 'Enable the browser-based operator surface',
    },
    {
        key: 'web.hostMode',
        type: 'enum',
        default: 'local',
        description: 'Network binding mode: local (127.0.0.1, default port), network (0.0.0.0, default port), custom (editable host and port)',
        enumValues: ['local', 'network', 'custom'],
    },
    {
        key: 'web.host',
        type: 'string',
        default: '127.0.0.1',
        description: 'Bind host for the web surface',
    },
    {
        key: 'web.port',
        type: 'number',
        default: 3423,
        description: 'Bind port for the web surface',
        validate: (v) => typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 65535,
    },
    {
        key: 'web.publicBaseUrl',
        type: 'string',
        default: 'http://127.0.0.1:3423',
        description: 'Public base URL for web links and ntfy/notification deep links',
    },
    {
        key: 'web.staticAssetsDir',
        type: 'string',
        default: 'dist/web',
        description: 'Static asset directory for the embedded web surface',
    },
];
export const runtimeSecondaryConfigSettings = [
    {
        key: 'watchers.enabled',
        type: 'boolean',
        default: false,
        description: 'Enable managed watcher/listener services',
    },
    {
        key: 'watchers.pollIntervalMs',
        type: 'number',
        default: 60_000,
        description: 'Polling interval for watcher sources in milliseconds',
        validate: (v) => typeof v === 'number' && Number.isInteger(v) && v >= 1_000 && v <= 24 * 60 * 60 * 1000,
    },
    {
        key: 'watchers.heartbeatIntervalMs',
        type: 'number',
        default: 15_000,
        description: 'Heartbeat interval for watcher services in milliseconds',
        validate: (v) => typeof v === 'number' && Number.isInteger(v) && v >= 1_000 && v <= 60 * 60 * 1000,
    },
    {
        key: 'watchers.recoveryWindowMinutes',
        type: 'number',
        default: 10,
        description: 'Recovery window for watcher restart and missed-event catch-up',
        validate: (v) => typeof v === 'number' && Number.isInteger(v) && v >= 0 && v <= 24 * 60,
    },
    {
        key: 'service.enabled',
        type: 'boolean',
        default: false,
        description: 'Enable service-install and daemon-management features',
    },
    {
        key: 'service.autostart',
        type: 'boolean',
        default: false,
        description: 'Start Goodvibes automatically when the host boots or logs in',
    },
    {
        key: 'service.restartOnFailure',
        type: 'boolean',
        default: true,
        description: 'Restart the service automatically after failure',
    },
    {
        key: 'service.platform',
        type: 'enum',
        default: 'auto',
        description: 'Target service manager platform',
        enumValues: ['auto', 'systemd', 'launchd', 'windows', 'manual'],
    },
    {
        key: 'service.serviceName',
        type: 'string',
        default: 'goodvibes',
        description: 'Service name used for host integration and install scripts',
    },
    {
        key: 'service.logPath',
        type: 'string',
        default: '',
        description: 'File path for daemon/service logs (empty = platform default under the configured service directory)',
    },
    {
        key: 'network.outboundTls.mode',
        type: 'enum',
        default: 'bundled',
        description: 'Outbound HTTPS trust mode for Bun fetch-based network calls',
        enumValues: ['bundled', 'bundled+custom', 'custom'],
    },
    {
        key: 'network.outboundTls.customCaFile',
        type: 'string',
        default: '',
        description: 'Additional PEM file to trust for outbound HTTPS when using bundled+custom or custom mode',
    },
    {
        key: 'network.outboundTls.customCaDir',
        type: 'string',
        default: '',
        description: 'Directory of PEM/CRT/CER files to trust for outbound HTTPS when using bundled+custom or custom mode',
    },
    {
        key: 'network.outboundTls.allowInsecureLocalhost',
        type: 'boolean',
        default: false,
        description: 'Allow self-signed HTTPS only for localhost/loopback outbound requests',
    },
    {
        key: 'network.remoteFetch.allowPrivateHosts',
        type: 'boolean',
        default: false,
        description: 'Allow explicit admin-approved remote fetches from private, localhost, or metadata hosts for artifacts and ingest flows',
    },
];
