mod app;
mod config;
mod diagnostics;
mod error;
mod media;
mod web;

use std::sync::Arc;

use clap::Parser;
use config::Config;
use tracing::info;

use crate::app::AppState;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt()
        .with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
        .init();

    let config = Config::parse().prepare()?;
    let listener = tokio::net::TcpListener::bind(config.bind).await?;
    info!(address = %config.bind, media_root = %config.media_root.display(), "lan-play started");
    let state = Arc::new(AppState::new(config)?);

    axum::serve(listener, app::router(state)).await?;
    Ok(())
}
