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 StructBanque de Sage 100c (IBOStructBanque3)
///
/// Représente une structure bancaire dans Sage 100c.
/// Définit les codes banque, guichet, compte et clé RIB.
#[derive(Debug)]
pub struct StructBanque {
    pub dispatch: IDispatch,
}

impl StructBanque {
    /// 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 structure bancaire
    pub fn sb_intitule(&self) -> SageResult<String> {
        self.dispatch()
            .call_method_by_name("SB_Intitule", &[])?
            .to_string()
    }

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

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

    /// Définit le code banque
    pub fn set_sb_code_banque(&self, code: &str) -> SageResult<()> {
        let param = SafeVariant::from_string(code);
        self.dispatch()
            .call_method_by_name("SetSB_CodeBanque", &[param])?;
        Ok(())
    }

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

    /// Définit le code guichet
    pub fn set_sb_code_guichet(&self, code: &str) -> SageResult<()> {
        let param = SafeVariant::from_string(code);
        self.dispatch()
            .call_method_by_name("SetSB_CodeGuichet", &[param])?;
        Ok(())
    }

    /// Récupère le numéro de compte
    pub fn sb_numero_compte(&self) -> SageResult<String> {
        self.dispatch()
            .call_method_by_name("SB_NumeroCompte", &[])?
            .to_string()
    }

    /// Définit le numéro de compte
    pub fn set_sb_numero_compte(&self, numero: &str) -> SageResult<()> {
        let param = SafeVariant::from_string(numero);
        self.dispatch()
            .call_method_by_name("SetSB_NumeroCompte", &[param])?;
        Ok(())
    }

    /// Récupère la clé RIB
    pub fn sb_cle_rib(&self) -> SageResult<String> {
        self.dispatch()
            .call_method_by_name("SB_CleRIB", &[])?
            .to_string()
    }

    /// Définit la clé RIB
    pub fn set_sb_cle_rib(&self, cle: &str) -> SageResult<()> {
        let param = SafeVariant::from_string(cle);
        self.dispatch()
            .call_method_by_name("SetSB_CleRIB", &[param])?;
        Ok(())
    }

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

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

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

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

    /// Retourne une description formatée de la structure bancaire
    pub fn description(&self) -> SageResult<String> {
        let intitule = self.sb_intitule()?;
        Ok(format!("StructBanque: {}", intitule))
    }
}

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

#[cfg(test)]
mod tests {
    #[test]
    fn test_struct_banque_properties() {
        // Test de documentation des propriétés disponibles
        // Propriétés principales: sb_intitule, sb_code_banque, sb_code_guichet,
        // sb_numero_compte, sb_cle_rib
        // Méthodes: write(), remove(), description()
    }
}