<?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/population-1.0.xsd"
    xmlns:dates="https://schemas.rutdev.se/xsd/types/dates-1.0.xsd"
    xmlns:strings="https://schemas.rutdev.se/xsd/types/strings-1.0.xsd"
    targetNamespace="https://schemas.rutdev.se/xsd/entities/level2/population-1.0.xsd"
    elementFormDefault="qualified"
    version="1.0">

    <!--
      Population Schema

      Description: Population is a specific subset of a universe that is defined with precise temporal and geographic boundaries. It represents the actual set of statistical units that exist at a particular point in tim...
      Version: 1.0
      Generated: 2026-04-22T06:56:44Z
      Source: specs/entities/level2/population-1.0.md
    -->

    <!-- Import common type definitions -->
    <xsd:import
        namespace="https://schemas.rutdev.se/xsd/types/dates-1.0.xsd"
        schemaLocation="../../../types/dates-1.0.xsd"
    />
    <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="PopulationPropertiesType">
        <xsd:sequence>
            <xsd:element name="IdAtOrigin" type="strings:IdentifierToken">
                <xsd:annotation>
                    <xsd:documentation>
                        Identifier at the source system for the population. 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:MultilingualShortString" minOccurs="0" maxOccurs="unbounded">
                <xsd:annotation>
                    <xsd:documentation>
                        The name of the population
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="Description" type="strings:MultilingualLongString" minOccurs="0" maxOccurs="unbounded">
                <xsd:annotation>
                    <xsd:documentation>
                        Detailed description of the population
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="EventPeriod" type="dates:DateRangeOpenEnded" minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>
                        The time period during which events occurred for this population. Absent start means the start date is historically unknown; absent end means the period is ongoing.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="ReferencePeriod" type="dates:DateRangeOpenEnded" minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>
                        The time period to which the population data refers. Absent start means the start date is historically unknown; absent end means the period is ongoing.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="Geography" type="strings:MultilingualLongString" minOccurs="0" maxOccurs="unbounded">
                <xsd:annotation>
                    <xsd:documentation>
                        Geographic scope or boundaries of the population
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>

    <!-- Relations type: all relationships use EntityReference -->
    <xsd:complexType name="PopulationRelationsType">
        <xsd:sequence>
            <xsd:element name="instantiatesUniverse" type="strings:EntityReference" minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>
                        Reference to Universe (instantiates universe)
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>

    <!-- Main entity type -->
    <xsd:complexType name="PopulationType">
        <xsd:sequence>
            <xsd:element name="properties" type="tns:PopulationPropertiesType" minOccurs="0"/>
            <xsd:element name="relations" type="tns:PopulationRelationsType" minOccurs="0"/>
        </xsd:sequence>
    </xsd:complexType>

    <!-- Collection type -->
    <xsd:complexType name="PopulationListType">
        <xsd:sequence>
            <xsd:element name="population" type="tns:PopulationType" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>

    <!-- Root elements -->
    <xsd:element name="Population" type="tns:PopulationType"/>
    <xsd:element name="PopulationList" type="tns:PopulationListType"/>

</xsd:schema>