use crate::{
    BusinessProcessModelAndNotation,
    elements::process::BPMNProcess,
    traits::{processable::Processable, writable::Writable},
};
use quick_xml::events::{BytesEnd, BytesStart, Event};

impl Writable for BPMNProcess {
    fn write<W: std::io::Write>(
        &self,
        x: &mut quick_xml::Writer<W>,
        _parent: &dyn Processable,
        bpmn: &BusinessProcessModelAndNotation,
    ) -> anyhow::Result<()> {
        x.write_event(Event::Start(BytesStart::new("process").with_attributes([
            ("id", self.id.as_str()),
            ("isExecutable", "true"),
        ])))?;

        self.elements.write(x, self, bpmn)?;

        self.sequence_flows.write(x, self, bpmn)?;

        x.write_event(Event::End(BytesEnd::new("process")))?;
        Ok(())
    }
}
