"""
Inscoper NBO Example Script: Object Accessors
=============================================
This script demonstrates how to read and write NBO attributes and children,
covering XSD primitives, optional values, complex children, and repeated
elements.

Prerequisites:
-------------
1. Installation: The `inscoper_nbo` wheel must be installed in the active Python
   environment.
"""

# --8<-- [start:main_logic]
import inscoper_nbo

# ── Step 1: XSD primitives map to native Python types
camera = inscoper_nbo.CMOS()
camera.setPixelWidth(6.5)                   # xsd:float  -> float
camera.setPixelWellCapacity(30000)          # xsd:long   -> int
camera.setManufacturer("Hamamatsu")         # xsd:string -> str

print(camera.getPixelWidth(), camera.getPixelWellCapacity(), camera.getManufacturer())

# ── Step 2: Optional values expose has / get / set / reset
# Reading an unset optional value raises InscoperNBOException rather than
# returning a placeholder, so the absence of a value is never silently ignored.
print(camera.hasArrayWidth())               # False

try:
    camera.getArrayWidth()
except inscoper_nbo.InscoperNBOException as error:
    print(f"ArrayWidth is not set: {error}")

camera.setArrayWidth(2048)
print(camera.hasArrayWidth(), camera.getArrayWidth())

camera.resetArrayWidth()                    # back to the unset state
print(camera.hasArrayWidth())

# ── Step 3: Complex children are objects, assigned through their own accessor
name = inscoper_nbo.Denomination_Type()
name.set("ORCA-Fusion BT")
camera.setName(name)
print(camera.getName().get())

# ── Step 4: Repeated elements are lists, assigned in bulk or one by one
reagent = inscoper_nbo.Reagent()

annotation_refs = inscoper_nbo.AnnotationRefVector()
annotation_refs.append(inscoper_nbo.AnnotationRef())
annotation_refs.append(inscoper_nbo.AnnotationRef())
reagent.setAnnotationRef_List(annotation_refs)
print(len(reagent.getAnnotationRef_List()))

reagent.addToAnnotationRef_List(inscoper_nbo.AnnotationRef())
print(len(reagent.getAnnotationRef_List()))

reagent.clearAnnotationRef_List()
print(len(reagent.getAnnotationRef_List()))
# --8<-- [end:main_logic]
