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 Dossier de Sage 100c (IBODossier3)
///
/// Représente un dossier comptable dans Sage 100c.
/// Contient les informations sur un dossier de l'entreprise.
#[derive(Debug)]
pub struct Dossier {
    pub dispatch: IDispatch,
}

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

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

    /// Récupère le nom du dossier
    pub fn d_nom(&self) -> SageResult<String> {
        self.dispatch()
            .call_method_by_name("D_Nom", &[])?
            .to_string()
    }

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

    /// Récupère la raison sociale du dossier
    pub fn d_raison_sociale(&self) -> SageResult<String> {
        self.dispatch()
            .call_method_by_name("D_RaisonSociale", &[])?
            .to_string()
    }

    /// Définit la raison sociale du dossier
    pub fn set_d_raison_sociale(&self, raison: &str) -> SageResult<()> {
        let param = SafeVariant::from_string(raison);
        self.dispatch()
            .call_method_by_name("SetD_RaisonSociale", &[param])?;
        Ok(())
    }

    /// Récupère le chemin du dossier
    pub fn d_chemin(&self) -> SageResult<String> {
        self.dispatch()
            .call_method_by_name("D_Chemin", &[])?
            .to_string()
    }

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

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

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

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

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

    /// Retourne une description formatée du dossier
    pub fn description(&self) -> SageResult<String> {
        let nom = self.d_nom()?;
        let raison = self.d_raison_sociale()?;
        Ok(format!("Dossier: {} - {}", nom, raison))
    }
}

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

#[cfg(test)]
mod tests {
    #[test]
    fn test_dossier_properties() {
        // Test de documentation des propriétés disponibles
        // Propriétés principales: d_nom, d_raison_sociale, d_chemin, d_code
        // Méthodes: write(), remove(), description()
    }
}