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 TiersStat de Sage 100c (IBOTiersStat3)
///
/// Représente une statistique de tiers dans Sage 100c.
/// Permet de définir des axes d'analyse statistiques pour les tiers.
#[derive(Debug)]
pub struct TiersStat {
    pub dispatch: IDispatch,
}

impl TiersStat {
    /// 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é de la statistique tiers
    pub fn ts_intitule(&self) -> SageResult<String> {
        self.dispatch()
            .call_method_by_name("TS_Intitule", &[])?
            .to_string()
    }

    /// Définit l'intitulé de la statistique tiers
    pub fn set_ts_intitule(&self, intitule: &str) -> SageResult<()> {
        let param = SafeVariant::from_string(intitule);
        self.dispatch()
            .call_method_by_name("SetTS_Intitule", &[param])?;
        Ok(())
    }

    /// Récupère le classement de la statistique
    pub fn ts_classement(&self) -> SageResult<String> {
        self.dispatch()
            .call_method_by_name("TS_Classement", &[])?
            .to_string()
    }

    /// Définit le classement de la statistique
    pub fn set_ts_classement(&self, classement: &str) -> SageResult<()> {
        let param = SafeVariant::from_string(classement);
        self.dispatch()
            .call_method_by_name("SetTS_Classement", &[param])?;
        Ok(())
    }

    /// Récupère le numéro de la statistique
    pub fn ts_numero(&self) -> SageResult<i32> {
        self.dispatch()
            .call_method_by_name("TS_Numero", &[])?
            .to_i32()
    }

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

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

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

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

    /// Retourne une description formatée de la statistique tiers
    pub fn description(&self) -> SageResult<String> {
        let intitule = self.ts_intitule()?;
        let numero = self.ts_numero()?;
        Ok(format!("TiersStat: {} - {}", numero, intitule))
    }
}

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

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