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

//! DocumentFormatting feature commands

use crate::app_context::AppContext;
use anyhow::{Context, Result};
use document_formatting::{
    MergeTextFormatDto, SetBlockFormatDto, SetFrameFormatDto, SetListFormatDto,
    SetTableCellFormatDto, SetTableFormatDto, SetTextFormatDto, document_formatting_controller,
};

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

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

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

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

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

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

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