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::{SafeDispatch, SafeVariant};
use crate::errors::SageResult;
use windows::Win32::System::Com::IDispatch;

/// ✅ IMPLÉMENTATION ENRICHIE - Version Phase 6
///
/// Wrapper pour glossaire commercial (IBSCIALGlossaire3)
///
/// Le glossaire commercial permet de définir des textes standardisés
/// réutilisables dans les documents commerciaux :
/// - Conditions générales de vente
/// - Clauses de garantie
/// - Mentions légales
/// - Textes promotionnels
/// - etc.
///
/// # Exemple
/// ```no_run
/// use objets_metier_rs::wrappers::cial::CialApplication;
///
/// let cial_app = CialApplication::new("Objets100c.CIAL")?;
/// let factory = cial_app.factory_glossaire()?;
///
/// let glossaire = factory.create()?;
/// glossaire.set_intitule("Conditions générales de vente")?;
/// glossaire.set_texte("Nos CGV...")?;
/// glossaire.write()?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
pub struct Glossaire {
    pub(crate) dispatch: IDispatch,
}

impl Glossaire {
    fn dispatch(&self) -> SafeDispatch<'_> {
        SafeDispatch::new(&self.dispatch)
    }

    // ═══════════════════════════════════════════════════════════════════════
    // PROPRIÉTÉS DE BASE (2 propriétés)
    // ═══════════════════════════════════════════════════════════════════════

    /// Identifiant unique (cbMarq)
    pub fn cbmarq(&self) -> SageResult<i32> {
        self.dispatch().call_method_by_name("cbMarq", &[])?.to_i32()
    }

    /// Intitulé de l'entrée du glossaire
    pub fn intitule(&self) -> SageResult<String> {
        self.dispatch()
            .call_method_by_name("Intitule", &[])?
            .to_string()
    }

    // ═══════════════════════════════════════════════════════════════════════
    // PROPRIÉTÉS DE CONTENU (4 propriétés)
    // ═══════════════════════════════════════════════════════════════════════

    /// Texte complet du glossaire
    pub fn texte(&self) -> SageResult<String> {
        self.dispatch()
            .call_method_by_name("Texte", &[])?
            .to_string()
    }

    /// Type de glossaire (0=En-tête, 1=Pied de page, 2=Corps de document)
    pub fn type_glossaire(&self) -> SageResult<i16> {
        self.dispatch()
            .call_method_by_name("TypeGlossaire", &[])?
            .to_short()
    }

    /// Langue du glossaire (FR, EN, DE, etc.)
    pub fn langue(&self) -> SageResult<String> {
        self.dispatch()
            .call_method_by_name("Langue", &[])?
            .to_string()
    }

    /// Actif (utilisable dans documents)
    pub fn actif(&self) -> SageResult<bool> {
        self.dispatch().call_method_by_name("Actif", &[])?.to_bool()
    }

    // ═══════════════════════════════════════════════════════════════════════
    // SETTERS (5 setters)
    // ═══════════════════════════════════════════════════════════════════════

    /// Modifie l'intitulé de l'entrée du glossaire
    pub fn set_intitule(&self, value: &str) -> SageResult<()> {
        let param = SafeVariant::from_string(value);
        self.dispatch().call_property_put("Intitule", &[param])?;
        Ok(())
    }

    /// Modifie le texte du glossaire
    pub fn set_texte(&self, texte: &str) -> SageResult<()> {
        let param = SafeVariant::from_string(texte);
        self.dispatch().call_property_put("Texte", &[param])?;
        Ok(())
    }

    /// Modifie le type de glossaire
    pub fn set_type_glossaire(&self, type_g: i16) -> SageResult<()> {
        let param = SafeVariant::from_i16(type_g);
        self.dispatch()
            .call_property_put("TypeGlossaire", &[param])?;
        Ok(())
    }

    /// Modifie la langue
    pub fn set_langue(&self, langue: &str) -> SageResult<()> {
        let param = SafeVariant::from_string(langue);
        self.dispatch().call_property_put("Langue", &[param])?;
        Ok(())
    }

    /// Active/désactive le glossaire
    pub fn set_actif(&self, actif: bool) -> SageResult<()> {
        let param = SafeVariant::from_bool(actif);
        self.dispatch().call_property_put("Actif", &[param])?;
        Ok(())
    }

    // ═══════════════════════════════════════════════════════════════════════
    // MÉTHODES STANDARD (3 méthodes)
    // ═══════════════════════════════════════════════════════════════════════

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

    /// Enregistre avec valeurs par défaut
    pub fn write_default(&self) -> SageResult<()> {
        self.dispatch().call_method_by_name("WriteDefault", &[])?;
        Ok(())
    }

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