qleany 1.7.3

Architecture generator for Rust and C++/Qt applications.
// Generated by Qleany v1.7.0 from frontend_entity_commands.tera

//! DtoField entity commands
#![allow(unused_imports, dead_code)]

use crate::app_context::AppContext;
use anyhow::{Context, Result};
use common::types::EntityId;
use direct_access::{CreateDtoFieldDto, DtoFieldDto, UpdateDtoFieldDto, dto_field_controller};

/// Create a new dto_field entity (orphan, no parent)
pub fn create_orphan_dto_field(
    ctx: &AppContext,
    stack_id: Option<u64>,
    dto: &CreateDtoFieldDto,
) -> Result<DtoFieldDto> {
    let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
    dto_field_controller::create_orphan(
        &ctx.db_context,
        &ctx.event_hub,
        &mut undo_redo_manager,
        stack_id,
        dto,
    )
    .context("creating dto_field")
}
/// Create a new dto_field entity as child of owner
pub fn create_dto_field(
    ctx: &AppContext,
    stack_id: Option<u64>,
    dto: &CreateDtoFieldDto,
    owner_id: EntityId,
    index: i32,
) -> Result<DtoFieldDto> {
    let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
    dto_field_controller::create(
        &ctx.db_context,
        &ctx.event_hub,
        &mut undo_redo_manager,
        stack_id,
        dto,
        owner_id,
        index,
    )
    .context("creating dto_field")
}
/// Create multiple dto_field entities (orphan, no parent)
pub fn create_orphan_dto_field_multi(
    ctx: &AppContext,
    stack_id: Option<u64>,
    dtos: &[CreateDtoFieldDto],
) -> Result<Vec<DtoFieldDto>> {
    let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
    dto_field_controller::create_orphan_multi(
        &ctx.db_context,
        &ctx.event_hub,
        &mut undo_redo_manager,
        stack_id,
        dtos,
    )
    .context("creating dto_field entities")
}
/// Create multiple dto_field entities as children of owner
pub fn create_dto_field_multi(
    ctx: &AppContext,
    stack_id: Option<u64>,
    dtos: &[CreateDtoFieldDto],
    owner_id: EntityId,
    index: i32,
) -> Result<Vec<DtoFieldDto>> {
    let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
    dto_field_controller::create_multi(
        &ctx.db_context,
        &ctx.event_hub,
        &mut undo_redo_manager,
        stack_id,
        dtos,
        owner_id,
        index,
    )
    .context("creating dto_field entities")
}
/// Get a dto_field entity by ID
pub fn get_dto_field(ctx: &AppContext, id: &EntityId) -> Result<Option<DtoFieldDto>> {
    dto_field_controller::get(&ctx.db_context, id).context("getting dto_field")
}

/// Get multiple dto_field entities by IDs
pub fn get_dto_field_multi(ctx: &AppContext, ids: &[EntityId]) -> Result<Vec<Option<DtoFieldDto>>> {
    dto_field_controller::get_multi(&ctx.db_context, ids).context("getting dto_field entities")
}

/// Get all dto_field entities.
/// Note: returns entities in database key order (by EntityId), not insertion order
/// or any user-defined sort. For ordered collections, use relationship-based
/// retrieval (e.g. get_*_relationship for ordered_one_to_many fields).
pub fn get_all_dto_field(ctx: &AppContext) -> Result<Vec<DtoFieldDto>> {
    dto_field_controller::get_all(&ctx.db_context).context("getting all dto_field entities")
}

/// Update a dto_field entity
pub fn update_dto_field(
    ctx: &AppContext,
    stack_id: Option<u64>,
    dto: &UpdateDtoFieldDto,
) -> Result<DtoFieldDto> {
    let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
    dto_field_controller::update(
        &ctx.db_context,
        &ctx.event_hub,
        &mut undo_redo_manager,
        stack_id,
        dto,
    )
    .context("updating dto_field")
}

/// Update multiple dto_field entities
pub fn update_dto_field_multi(
    ctx: &AppContext,
    stack_id: Option<u64>,
    dtos: &[UpdateDtoFieldDto],
) -> Result<Vec<DtoFieldDto>> {
    let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
    dto_field_controller::update_multi(
        &ctx.db_context,
        &ctx.event_hub,
        &mut undo_redo_manager,
        stack_id,
        dtos,
    )
    .context("updating dto_field entities")
}

/// Update a dto_field entity with relationships
pub fn update_dto_field_with_relationships(
    ctx: &AppContext,
    stack_id: Option<u64>,
    dto: &DtoFieldDto,
) -> Result<DtoFieldDto> {
    let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
    dto_field_controller::update_with_relationships(
        &ctx.db_context,
        &ctx.event_hub,
        &mut undo_redo_manager,
        stack_id,
        dto,
    )
    .context("updating dto_field with relationships")
}

/// Update multiple dto_field entities with relationships
pub fn update_dto_field_with_relationships_multi(
    ctx: &AppContext,
    stack_id: Option<u64>,
    dtos: &[DtoFieldDto],
) -> Result<Vec<DtoFieldDto>> {
    let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
    dto_field_controller::update_with_relationships_multi(
        &ctx.db_context,
        &ctx.event_hub,
        &mut undo_redo_manager,
        stack_id,
        dtos,
    )
    .context("updating dto_field entities with relationships")
}

/// Remove a dto_field entity by ID
pub fn remove_dto_field(ctx: &AppContext, stack_id: Option<u64>, id: &EntityId) -> Result<()> {
    let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
    dto_field_controller::remove(
        &ctx.db_context,
        &ctx.event_hub,
        &mut undo_redo_manager,
        stack_id,
        id,
    )
    .context("removing dto_field")
}

/// Remove multiple dto_field entities by IDs
pub fn remove_dto_field_multi(
    ctx: &AppContext,
    stack_id: Option<u64>,
    ids: &[EntityId],
) -> Result<()> {
    let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
    dto_field_controller::remove_multi(
        &ctx.db_context,
        &ctx.event_hub,
        &mut undo_redo_manager,
        stack_id,
        ids,
    )
    .context("removing dto_field entities")
}