/*
    This file is part of jellything (https://codeberg.org/metamuffin/jellything)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    Copyright (C) 2026 metamuffin <metamuffin.org>
*/

use clap::Parser;
use jellytool::{
    add::add,
    cli::{Action, Args},
    migrate::migrate,
};

fn main() -> anyhow::Result<()> {
    env_logger::builder()
        .filter_level(log::LevelFilter::Info)
        .parse_env("LOG")
        .init();
    let args = Args::parse();

    match args {
        a @ Action::Add { .. } => {
            let rt = tokio::runtime::Builder::new_multi_thread()
                .enable_all()
                .build()
                .unwrap();
            add(a, rt.handle())
        }
        a @ Action::Migrate { .. } => migrate(a),
        _ => Ok(()),
        // Action::Reimport {
        //     hostname,
        //     no_tls,
        //     no_incremental,
        // } => tokio::runtime::Builder::new_multi_thread()
        //     .enable_all()
        //     .build()
        //     .unwrap()
        //     .block_on(async move {
        //         let inst = Instance::new(hostname.unwrap_or(CONF.hostname.clone()), !no_tls);
        //         info!("login");
        //         let session = inst
        //             .login(CreateSessionParams {
        //                 drop_permissions: None,
        //                 expire: None,
        //                 password: SECRETS
        //                     .admin_password
        //                     .clone()
        //                     .ok_or(anyhow!("admin account required"))?,
        //                 username: CONF
        //                     .admin_username
        //                     .clone()
        //                     .ok_or(anyhow!("admin account required"))?,
        //             })
        //             .await?;

        //         session.reimport(!no_incremental).await?;
        //         Ok(())
        //     }),
    }
}
