//! Partition node binary — entry point for each Kubernetes pod.
//!
//! Reads configuration from environment variables, loads assigned partitions
//! from object storage, and serves them via Arrow Flight RPC until a shutdown
//! signal is received.
//!
//! ## Usage
//!
//! ```bash
//! # Build
//! cargo build --bin partition_node --features distributed --release
//!
//! # Run locally
//! POD_NAME=ocg-partition-0 \
//! ETCD_ENDPOINTS=http://localhost:2379 \
//! S3_BUCKET=ocg-graph-data \
//! S3_PREFIX=graphs/my-graph \
//!   ./target/release/partition_node
//! ```

#[cfg(feature = "distributed")]
use ocg::distributed::pod::PodConfig;
#[cfg(feature = "distributed")]
use ocg::distributed::pod::PodStartup;

#[cfg(feature = "distributed")]
#[tokio::main]
async fn main() {
    // Initialise tracing subscriber — respects RUST_LOG env var
    tracing_subscriber::fmt()
        .with_env_filter(
            tracing_subscriber::EnvFilter::from_default_env()
                .add_directive("ocg=info".parse().unwrap()),
        )
        .init();

    let config = match PodConfig::from_env() {
        Ok(c)  => c,
        Err(e) => {
            eprintln!("Configuration error: {e}");
            std::process::exit(1);
        }
    };

    tracing::info!(
        pod        = %config.pod_name,
        partitions = ?config.partition_ids,
        "partition_node starting"
    );

    if let Err(e) = PodStartup::new(config).run().await {
        tracing::error!("partition_node error: {e}");
        std::process::exit(1);
    }
}

#[cfg(not(feature = "distributed"))]
fn main() {
    eprintln!(
        "partition_node requires the 'distributed' feature.\n\
         Build with: cargo build --bin partition_node --features distributed"
    );
    std::process::exit(1);
}
