mod error;
mod index;
mod metrics;
mod searcher;
mod server;
mod state;

use anyhow::Result;
use clap::Parser;

#[derive(Parser)]
#[command(
    name = "serving-service",
    version,
    arg_required_else_help(true),
    about = "FTS Serving Service for Qdrant on TiDB Serverless."
)]
struct Args {
    #[arg(
        id = "cert",
        long = "cert",
        env = "CERT_PATH",
        default_value = "tls.crt",
        help = "Certificate file in PEM format.",
        num_args(1)
    )]
    tls_cert: String,
    #[arg(
        id = "key",
        long = "key",
        env = "KEY_PATH",
        default_value = "tls.key",
        help = "X509 key in PEM format.",
        num_args(1)
    )]
    tls_key: String,
    #[arg(
        id = "cacert",
        long = "cacert",
        env = "CA_PATH",
        default_value = "ca.crt",
        help = "CA certificate file in PEM format.",
        num_args(1)
    )]
    // TODO(iosmanthus): Apply this CA certificate to those in-cluster http clients
    tls_ca: String,
    #[arg(
        id = "storage-path",
        long = "storage-path",
        env = "STORAGE_PATH",
        default_value = "data",
        help = "Path to storage",
        num_args(1)
    )]
    path: String,
    #[arg(
        id = "locally",
        long = "locally",
        env = "LOCAL",
        help = "load index form locally or cloud",
        default_value = "false"
    )]
    locally: bool,
}

#[tokio::main]
#[allow(clippy::needless_return)]
async fn main() -> Result<()> {
    env_logger::init();
    server::serve(Args::parse()).await
}
