pub(crate) mod attach;
mod caffeinate;
mod cleanup;
mod discovery;
mod identity;
mod image;
mod launch;
mod naming;
mod repo_cache;

#[cfg(test)]
pub mod test_support;

#[cfg(test)]
pub use self::test_support::FakeRunner;

pub(crate) use self::attach::docker_unavailable_msg;
pub use self::attach::{
    AgentSession, AgentSessionInventory, ContainerState, describe_agent_session_count,
    hardline_agent, inspect_agent_sessions, inspect_hardline_instance, spawn_agent_session,
    spawn_shell_session,
};
pub use self::caffeinate::reconcile as reconcile_keep_awake;
pub use self::cleanup::{
    eject_role, exile_all, prune_all_instances, prune_cache, prune_images, prune_instances,
    prune_jackin_home, prune_roles, purge_class_data, purge_container_state,
};
pub(crate) use self::discovery::list_role_names;
pub use self::discovery::{
    list_managed_role_names, list_running_agent_display_names, list_running_agent_names,
};
pub use self::launch::{LoadOptions, load_role};
pub use self::naming::matching_family;
pub(crate) use self::repo_cache::{RepoError, normalize_github_url};

pub(crate) async fn register_agent_repo(
    paths: &crate::paths::JackinPaths,
    selector: &crate::selector::RoleSelector,
    git_url: &str,
    runner: &mut impl crate::docker::CommandRunner,
    debug: bool,
    persist_registration: impl FnOnce() -> anyhow::Result<()>,
) -> anyhow::Result<(crate::repo::CachedRepo, crate::repo::ValidatedRoleRepo)> {
    self::repo_cache::register_agent_repo(
        paths,
        selector,
        git_url,
        runner,
        debug,
        persist_registration,
    )
    .await
}
