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 Rappel de Sage 100c (IBORappel3)
///
/// Représente un rappel dans Sage 100c.
/// Permet de gérer les rappels de paiement aux clients.
#[derive(Debug)]
pub struct Rappel {
    pub dispatch: IDispatch,
}

impl Rappel {
    /// 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 rappel
    pub fn r_intitule(&self) -> SageResult<String> {
        self.dispatch()
            .call_method_by_name("R_Intitule", &[])?
            .to_string()
    }

    /// Définit l'intitulé du rappel
    pub fn set_r_intitule(&self, intitule: &str) -> SageResult<()> {
        let param = SafeVariant::from_string(intitule);
        self.dispatch()
            .call_method_by_name("SetR_Intitule", &[param])?;
        Ok(())
    }

    /// Récupère le numéro du rappel
    pub fn r_numero(&self) -> SageResult<i32> {
        self.dispatch()
            .call_method_by_name("R_Numero", &[])?
            .to_i32()
    }

    /// Définit le numéro du rappel
    pub fn set_r_numero(&self, numero: i32) -> SageResult<()> {
        let param = SafeVariant::I4(numero);
        self.dispatch()
            .call_method_by_name("SetR_Numero", &[param])?;
        Ok(())
    }

    /// Récupère le niveau du rappel (1, 2, 3...)
    pub fn r_niveau(&self) -> SageResult<i32> {
        self.dispatch()
            .call_method_by_name("R_Niveau", &[])?
            .to_i32()
    }

    /// Définit le niveau du rappel
    pub fn set_r_niveau(&self, niveau: i32) -> SageResult<()> {
        let param = SafeVariant::I4(niveau);
        self.dispatch()
            .call_method_by_name("SetR_Niveau", &[param])?;
        Ok(())
    }

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

    /// Sauvegarde les modifications du rappel
    pub fn write(&self) -> SageResult<()> {
        self.dispatch().call_method_by_name("Write", &[])?;
        Ok(())
    }

    /// Supprime le rappel
    pub fn remove(&self) -> SageResult<()> {
        self.dispatch().call_method_by_name("Remove", &[])?;
        Ok(())
    }

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

    /// Retourne une description formatée du rappel
    pub fn description(&self) -> SageResult<String> {
        let intitule = self.r_intitule()?;
        let niveau = self.r_niveau()?;
        Ok(format!("Rappel: {} (niveau {})", intitule, niveau))
    }
}

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

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