package config

// NodeConfig is the top-level configuration for a standalone Node.
type NodeConfig struct {
	Transport       TransportConf           `mapstructure:"transport" yaml:"transport"`
	CredentialPlane NodeCredentialPlaneConf `mapstructure:"credential_plane" yaml:"credential_plane,omitempty"`
	Reconnect       ReconnectConf           `mapstructure:"reconnect" yaml:"reconnect"`
	Logging         LoggingConf             `mapstructure:"logging"   yaml:"logging"`
	Metrics         MetricsConf             `mapstructure:"metrics"   yaml:"metrics"`
}

// ReconnectConf controls how the Node connectivity supervisor retries the
// initial dial and post-disconnect reconnects to Edge. The same policy applies
// to both the initial connect and established-session reconnect paths.
type ReconnectConf struct {
	// IntervalSec is the delay between connect attempts. An omitted value keeps
	// the default 10s; it must be positive when MaxAttempts is 0 (unlimited) so
	// the supervisor cannot hot-loop. Negative values are a config error.
	IntervalSec int `mapstructure:"interval_sec" yaml:"interval_sec"`
	// MaxAttempts bounds retries per connect episode. An omitted value keeps the
	// default 10; an explicit 0 means unlimited retries until local shutdown; a
	// positive value is a finite limit whose exhaustion terminates the Node with
	// a non-zero exit code. Negative values are a config error.
	MaxAttempts int `mapstructure:"max_attempts" yaml:"max_attempts"`
}

// TransportConf carries the Edge address and registration token for a Node.
type TransportConf struct {
	EdgeAddr string  `mapstructure:"edge_addr" yaml:"edge_addr"`
	Token    string  `mapstructure:"token"     yaml:"token"`
	TLS      TLSConf `mapstructure:"tls"       yaml:"tls,omitempty"`
}

// NodeCredentialPlaneConf owns the Node X25519 recipient identity and trusted
// Control Plane Ed25519 issuer public key. Key bytes are loaded from strict
// deployment files and are never embedded in tracked configuration.
type NodeCredentialPlaneConf struct {
	Enabled             bool   `mapstructure:"enabled"               yaml:"enabled"`
	RecipientKeyID      string `mapstructure:"recipient_key_id"      yaml:"recipient_key_id,omitempty"`
	RecipientPrivateKey string `mapstructure:"recipient_private_key" yaml:"recipient_private_key,omitempty"`
	IssuerKeyID         string `mapstructure:"issuer_key_id"         yaml:"issuer_key_id,omitempty"`
	IssuerPublicKey     string `mapstructure:"issuer_public_key"     yaml:"issuer_public_key,omitempty"`
	ReplayCacheSize     int    `mapstructure:"replay_cache_size"     yaml:"replay_cache_size,omitempty"`
}

// RuntimeConf carries legacy node-wide concurrency metadata.
// Runtime admission must use provider/resource capacity rather than
// treating this as a node-wide gate.
type RuntimeConf struct {
	Concurrency int `mapstructure:"concurrency" yaml:"concurrency"`
}
