<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:tns="https://schemas.rutdev.se/xsd/entities/level2/instance-variable-1.0.xsd"
    xmlns:strings="https://schemas.rutdev.se/xsd/types/strings-1.0.xsd"
    targetNamespace="https://schemas.rutdev.se/xsd/entities/level2/instance-variable-1.0.xsd"
    elementFormDefault="qualified"
    version="1.0">

    <!--
      InstanceVariable Schema

      Description: InstanceVariable is a variable that observes a specific population using a particular representation. It represents the concrete instantiation of a represented variable for a specific population, link...
      Version: 1.0
      Generated: 2026-04-22T06:56:44Z
      Source: specs/entities/level2/instance-variable-1.0.md
    -->

    <!-- Import common type definitions -->
    <xsd:import
        namespace="https://schemas.rutdev.se/xsd/types/strings-1.0.xsd"
        schemaLocation="../../../types/strings-1.0.xsd"
    />

    <!-- Properties type: all data fields from entity specification -->
    <xsd:complexType name="InstanceVariablePropertiesType">
        <xsd:sequence>
            <xsd:element name="IdAtOrigin" type="strings:IdentifierToken">
                <xsd:annotation>
                    <xsd:documentation>
                        Identifier at the source system for the instance-variable. Used during import to determine if the entity already exists in the target system (update) or is new (create). Must remain stable in the source system for the same entity.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="Name" type="strings:MultilingualText" minOccurs="0" maxOccurs="unbounded">
                <xsd:annotation>
                    <xsd:documentation>
                        The designation of the instance variable
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="Description" type="strings:MultilingualText" minOccurs="0" maxOccurs="unbounded">
                <xsd:annotation>
                    <xsd:documentation>
                        Explanation of the instance variable
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="Definition" type="strings:MultilingualText" minOccurs="0" maxOccurs="unbounded">
                <xsd:annotation>
                    <xsd:documentation>
                        The operational definition of the variable in context, describing how it is concretely measured or observed. Corresponds to the GSIM Concept.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>

    <!-- Relations type: all relationships use EntityReference -->
    <xsd:complexType name="InstanceVariableRelationsType">
        <xsd:sequence>
            <xsd:element name="observesPopulation" type="strings:EntityReference" minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>
                        Reference to Population (observes population)
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="usesRepresentation" type="strings:EntityReference" minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>
                        Reference to RepresentedVariable (uses representation)
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="belongsToDataset" type="strings:EntityReference" minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>
                        Reference to Dataset (belongs to dataset)
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>

    <!-- Main entity type -->
    <xsd:complexType name="InstanceVariableType">
        <xsd:sequence>
            <xsd:element name="properties" type="tns:InstanceVariablePropertiesType" minOccurs="0"/>
            <xsd:element name="relations" type="tns:InstanceVariableRelationsType" minOccurs="0"/>
        </xsd:sequence>
    </xsd:complexType>

    <!-- Collection type -->
    <xsd:complexType name="InstanceVariableListType">
        <xsd:sequence>
            <xsd:element name="instanceVariable" type="tns:InstanceVariableType" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>

    <!-- Root elements -->
    <xsd:element name="InstanceVariable" type="tns:InstanceVariableType"/>
    <xsd:element name="InstanceVariableList" type="tns:InstanceVariableListType"/>

</xsd:schema>