// Generated by Qleany. Edit at your own risk! Be careful when regenerating this file
// as changes will be lost.

use crate::GetDiffDto;
use crate::GetDiffReturnDto;
use crate::units_of_work::fill_status_in_files_uow::FillStatusInFilesUnitOfWorkFactory;
use crate::units_of_work::get_file_diff_uow::GetFileDiffUnitOfWorkFactory;
use crate::use_cases::fill_status_in_files_uc::FillStatusInFilesUseCase;
use crate::use_cases::get_file_diff_uc::GetFileDiffUseCase;
use anyhow::Result;
use common::event::{Event, Origin};

use common::event::FileGenerationSharedStepsEvent::FillStatusInFiles;
use common::event::FileGenerationSharedStepsEvent::GetFileDiff;

use common::{database::db_context::DbContext, event::EventHub};
use std::sync::Arc;

pub fn fill_status_in_files(db_context: &DbContext, event_hub: &Arc<EventHub>) -> Result<()> {
    let uow_context = FillStatusInFilesUnitOfWorkFactory::new(db_context, event_hub);
    let mut uc = FillStatusInFilesUseCase::new(Box::new(uow_context));
    uc.execute()?;
    // Notify that the handling manifest has been loaded
    event_hub.send_event(Event {
        origin: Origin::FileGenerationSharedSteps(FillStatusInFiles),
        ids: vec![],
        data: None,
    });
    Ok(())
}

pub fn get_file_diff(
    db_context: &DbContext,
    event_hub: &Arc<EventHub>,
    dto: &GetDiffDto,
) -> Result<GetDiffReturnDto> {
    let uow_context = GetFileDiffUnitOfWorkFactory::new(db_context);
    let mut uc = GetFileDiffUseCase::new(Box::new(uow_context));
    let return_dto = uc.execute(dto)?;
    // Notify that the handling manifest has been loaded
    event_hub.send_event(Event {
        origin: Origin::FileGenerationSharedSteps(GetFileDiff),
        ids: vec![],
        data: None,
    });
    Ok(return_dto)
}
