objets_metier_rs 1.0.2

Bibliothèque Rust moderne et sûre pour l'API COM Objets Métier Sage 100c - Production Ready
use crate::com::{SafeDispatch, SafeVariant};
use crate::errors::SageResult;
use windows::Win32::System::Com::IDispatch;

/// Collection d'erreurs du processus (IFailInfoCol)
/// Utilisée pour récupérer les erreurs de validation d'un processus IPMEncoder
pub struct ErrorCollection {
    pub dispatch: IDispatch,
}

impl ErrorCollection {
    fn dispatch(&self) -> SafeDispatch<'_> {
        SafeDispatch::new(&self.dispatch)
    }

    /// Nombre d'erreurs dans la collection
    pub fn count(&self) -> SageResult<i32> {
        self.dispatch().get_property_by_name("Count")?.to_i32()
    }

    /// Récupère une erreur par index (1-based comme en VB)
    pub fn item(&self, index: i32) -> SageResult<FailInfo> {
        let index_variant = SafeVariant::I4(index);
        let result = self
            .dispatch()
            .call_method_by_name("Item", &[index_variant])?;

        let dispatch = result.to_dispatch()?;
        Ok(FailInfo { dispatch })
    }
}

/// Information sur une erreur (IFailInfo)
/// Contient les détails d'une erreur de validation d'un processus
pub struct FailInfo {
    pub dispatch: IDispatch,
}

impl FailInfo {
    fn dispatch(&self) -> SafeDispatch<'_> {
        SafeDispatch::new(&self.dispatch)
    }

    /// Code d'erreur Sage
    pub fn error_code(&self) -> SageResult<i32> {
        self.dispatch().get_property_by_name("ErrorCode")?.to_i32()
    }

    /// Indice de l'élément en erreur
    pub fn indice(&self) -> SageResult<i32> {
        self.dispatch().get_property_by_name("Indice")?.to_i32()
    }

    /// Description de l'erreur
    pub fn text(&self) -> SageResult<String> {
        self.dispatch().get_property_by_name("Text")?.to_string()
    }
}