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::{FromDispatchNew, SafeDispatch, SafeVariant};
use crate::errors::SageResult;
use windows::Win32::System::Com::IDispatch;

/// Wrapper pour l'objet ModeleEcriture de Sage 100c (IBOModeleEcriture3)
///
/// Représente un modèle d'écriture dans Sage 100c.
/// Permet de créer des modèles pré-définis d'écritures comptables.
#[derive(Debug)]
pub struct ModeleEcriture {
    pub dispatch: IDispatch,
}

impl ModeleEcriture {
    /// Crée un SafeDispatch temporaire pour les appels
    fn dispatch(&self) -> SafeDispatch<'_> {
        SafeDispatch::new(&self.dispatch)
    }

    // ==================== PROPRIÉTÉS PRINCIPALES ====================

    /// Récupère l'intitulé du modèle d'écriture
    pub fn me_intitule(&self) -> SageResult<String> {
        self.dispatch()
            .call_method_by_name("ME_Intitule", &[])?
            .to_string()
    }

    /// Définit l'intitulé du modèle d'écriture
    pub fn set_me_intitule(&self, intitule: &str) -> SageResult<()> {
        let param = SafeVariant::from_string(intitule);
        self.dispatch()
            .call_method_by_name("SetME_Intitule", &[param])?;
        Ok(())
    }

    /// Récupère le code du modèle
    pub fn me_code(&self) -> SageResult<String> {
        self.dispatch()
            .call_method_by_name("ME_Code", &[])?
            .to_string()
    }

    /// Définit le code du modèle
    pub fn set_me_code(&self, code: &str) -> SageResult<()> {
        let param = SafeVariant::from_string(code);
        self.dispatch()
            .call_method_by_name("SetME_Code", &[param])?;
        Ok(())
    }

    // ==================== MÉTHODES IBIPersistObject ====================

    /// Sauvegarde les modifications du modèle d'écriture
    pub fn write(&self) -> SageResult<()> {
        self.dispatch().call_method_by_name("Write", &[])?;
        Ok(())
    }

    /// Supprime le modèle d'écriture
    pub fn remove(&self) -> SageResult<()> {
        self.dispatch().call_method_by_name("Remove", &[])?;
        Ok(())
    }

    // ==================== MÉTHODES DE DESCRIPTION ====================

    /// Retourne une description formatée du modèle d'écriture
    pub fn description(&self) -> SageResult<String> {
        let intitule = self.me_intitule()?;
        Ok(format!("ModeleEcriture: {}", intitule))
    }
}

impl FromDispatchNew for ModeleEcriture {
    fn from_dispatch_new(dispatch: IDispatch) -> SageResult<Self> {
        Ok(Self { dispatch })
    }
}

#[cfg(test)]
mod tests {
    #[test]
    fn test_modele_ecriture_properties() {
        // Test de documentation des propriétés disponibles
        // Propriétés principales: me_intitule, me_code
        // Méthodes: write(), remove(), description()
    }
}