// Generated by Qleany v1.4.8 from frontend_feature_commands.tera

//! DocumentSearch feature commands

use crate::app_context::AppContext;
use anyhow::{Context, Result};
use document_search::{
    FindAllDto, FindAllResultDto, FindResultDto, FindTextDto, ReplaceResultDto, ReplaceTextDto,
    document_search_controller,
};

pub fn find_text(ctx: &AppContext, dto: &FindTextDto) -> Result<FindResultDto> {
    document_search_controller::find_text(&ctx.db_context, &ctx.event_hub, dto).context("find_text")
}

pub fn find_all(ctx: &AppContext, dto: &FindAllDto) -> Result<FindAllResultDto> {
    document_search_controller::find_all(&ctx.db_context, &ctx.event_hub, dto).context("find_all")
}

pub fn replace_text(
    ctx: &AppContext,
    stack_id: Option<u64>,
    dto: &ReplaceTextDto,
) -> Result<ReplaceResultDto> {
    let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
    document_search_controller::replace_text(
        &ctx.db_context,
        &ctx.event_hub,
        &mut undo_redo_manager,
        stack_id,
        dto,
    )
    .context("replace_text")
}
