use std::ops::ControlFlow;

use crate::parser::ListItem;

use super::state::ReplContext;

mod function;
mod index;
mod pattern;
mod schema;
mod sequence;
mod table;
mod view;

pub async fn handle_list(
	ctx: &mut ReplContext<'_>,
	item: ListItem,
	pattern: String,
	detail: bool,
	sameconn: bool,
) -> ControlFlow<()> {
	match item {
		ListItem::Table => table::handle_list_tables(ctx, &pattern, detail, sameconn).await,
		ListItem::Index => index::handle_list_indexes(ctx, &pattern, detail, sameconn).await,
		ListItem::Function => {
			function::handle_list_functions(ctx, &pattern, detail, sameconn).await
		}
		ListItem::View => view::handle_list_views(ctx, &pattern, detail, sameconn).await,
		ListItem::Schema => schema::handle_list_schemas(ctx, &pattern, detail, sameconn).await,
		ListItem::Sequence => {
			sequence::handle_list_sequences(ctx, &pattern, detail, sameconn).await
		}
	}
}
