"""
Inscoper NBO Example Script: First Instrument
============================================
This script demonstrates how to build a minimal NBO Instrument, attach a
microscope stand to it, and serialize the result as NBO-XML.

Prerequisites:
-------------
1. Installation: The `inscoper_nbo` wheel must be installed in the active Python
   environment.
"""

# --8<-- [start:main_logic]
import inscoper_nbo

# Every NBO element is a plain Python object
instrument = inscoper_nbo.Instrument()

# Identifiers are restricted types: instantiate, validate through set(), then assign
instrument_id = inscoper_nbo.InstrumentID_Type()
instrument_id.set("Instrument:1")
instrument.setID(instrument_id)

name = inscoper_nbo.Denomination_Type()
name.set("Nikon Ti2 - Room 214")
instrument.setName(name)

# The stand is a child of the instrument. MicroscopeStand is abstract in the
# schema, so the concrete class states the geometry of the stand.
stand = inscoper_nbo.InvertedMicroscopeStand()

stand_id = inscoper_nbo.LSID_Type()
stand_id.set("MicroscopeStand:1")
stand.setID(stand_id)

# Plain XSD primitives are set with native Python values
stand.setManufacturer("Nikon")
stand.setModel("Eclipse Ti2-E")
stand.setCatalogNumber("Ti2-E")

stand_type = inscoper_nbo.MicroscopeType_Type()
stand_type.set("Compound")
stand.setType(stand_type)

instrument.addToMicroscopeStandGroup_List(stand)

# Serialize the whole tree as NBO-XML. Export validates the document, so an
# element that lacks a required attribute is reported here rather than accepted.
print(instrument.toXmlString())
# --8<-- [end:main_logic]
