/*
 * Inscoper NBO Example: Object Accessors
 * ======================================
 * This example demonstrates how to read and write NBO attributes and children,
 * covering XSD primitives, optional values, complex children, and repeated
 * elements.
 *
 * Prerequisites:
 * -------------
 * 1. Installation: inscoper-nbo-<version>.jar must be on the classpath.
 */

// --8<-- [start:main_logic]
import com.inscoper.nbo.AnnotationRef;
import com.inscoper.nbo.AnnotationRefVector;
import com.inscoper.nbo.CMOS;
import com.inscoper.nbo.Denomination_Type;
import com.inscoper.nbo.Reagent;

public class ObjectAccessors {
    public static void main(String[] args) {
        // Step 1: XSD primitives map to native Java types
        CMOS camera = new CMOS();
        camera.setPixelWidth(6.5f);            // xsd:float  -> float
        camera.setPixelWellCapacity(30000L);   // xsd:long   -> long
        camera.setManufacturer("Hamamatsu");   // xsd:string -> String

        System.out.println(camera.getPixelWidth() + " " + camera.getPixelWellCapacity() + " "
                + camera.getManufacturer());

        // Step 2: Optional values expose has / get / set / reset
        // Reading an unset optional value throws InscoperNBOException rather than
        // returning a placeholder, so the absence of a value is never silently ignored.
        System.out.println(camera.hasArrayWidth());   // false

        // The generated getters carry no throws clause, so the checked exception
        // cannot be named in a catch block: catch Exception and read its message.
        try {
            camera.getArrayWidth();
        } catch (Exception error) {
            System.out.println("ArrayWidth is not set: " + error.getMessage());
        }

        camera.setArrayWidth(2048L);
        System.out.println(camera.hasArrayWidth() + " " + camera.getArrayWidth());

        camera.resetArrayWidth();                     // back to the unset state
        System.out.println(camera.hasArrayWidth());

        // Step 3: Complex children are objects, assigned through their own accessor
        Denomination_Type name = new Denomination_Type();
        name.set("ORCA-Fusion BT");
        camera.setName(name);
        System.out.println(camera.getName().get());

        // Step 4: Repeated elements are typed vectors, assigned in bulk or one by one
        Reagent reagent = new Reagent();

        AnnotationRefVector annotationRefs = new AnnotationRefVector();
        annotationRefs.add(new AnnotationRef());
        annotationRefs.add(new AnnotationRef());
        reagent.setAnnotationRef_List(annotationRefs);
        System.out.println(reagent.getAnnotationRef_List().size());

        reagent.addToAnnotationRef_List(new AnnotationRef());
        System.out.println(reagent.getAnnotationRef_List().size());

        reagent.clearAnnotationRef_List();
        System.out.println(reagent.getAnnotationRef_List().size());
    }
}
// --8<-- [end:main_logic]
