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 CompteA de Sage 100c (IBOCompteA3)
pub struct CompteA {
    pub dispatch: IDispatch,
}

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

    /// Récupère le numéro du compte analytique
    pub fn get_numero(&self) -> SageResult<String> {
        let result = self.dispatch().get_property_by_name("Numero")?;
        result.to_string()
    }

    /// Récupère l'intitulé du compte analytique
    pub fn get_intitule(&self) -> SageResult<String> {
        let result = self.dispatch().get_property_by_name("Intitule")?;
        result.to_string()
    }

    // ==================== SETTERS POUR PROPRIÉTÉS ====================

    /// Définit le numéro du compte analytique
    pub fn set_numero(&self, numero: &str) -> SageResult<()> {
        let numero_variant = SafeVariant::from_string(numero);
        self.dispatch()
            .call_property_put("Numero", &[numero_variant])?;
        Ok(())
    }

    /// Définit l'intitulé du compte analytique
    pub fn set_intitule(&self, intitule: &str) -> SageResult<()> {
        let intitule_variant = SafeVariant::from_string(intitule);
        self.dispatch()
            .call_property_put("Intitule", &[intitule_variant])?;
        Ok(())
    }
}

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