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 ServiceContact de Sage 100c (IBOServiceContact3)
///
/// Représente un service de contact dans Sage 100c.
/// Permet de catégoriser les contacts par service.
#[derive(Debug)]
pub struct ServiceContact {
    pub dispatch: IDispatch,
}

impl ServiceContact {
    /// 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 service de contact
    pub fn sc_intitule(&self) -> SageResult<String> {
        self.dispatch()
            .call_method_by_name("SC_Intitule", &[])?
            .to_string()
    }

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

    /// Récupère le classement du service
    pub fn sc_classement(&self) -> SageResult<String> {
        self.dispatch()
            .call_method_by_name("SC_Classement", &[])?
            .to_string()
    }

    /// Définit le classement du service
    pub fn set_sc_classement(&self, classement: &str) -> SageResult<()> {
        let param = SafeVariant::from_string(classement);
        self.dispatch()
            .call_method_by_name("SetSC_Classement", &[param])?;
        Ok(())
    }

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

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

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

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

    /// Retourne une description formatée du service de contact
    pub fn description(&self) -> SageResult<String> {
        let intitule = self.sc_intitule()?;
        Ok(format!("ServiceContact: {}", intitule))
    }
}

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

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