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

    <!--
      Dataset Schema

      Description: Dataset is an organized collection of data structured according to data structure specifications. In this model a Dataset describes the metadata about a particular set of actual statistical observatio...
      Version: 1.0
      Generated: 2026-04-22T06:56:44Z
      Source: specs/entities/level1/dataset-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/enums-1.0.xsd"
        schemaLocation="../../../types/enums-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="DatasetPropertiesType">
        <xsd:sequence>
            <xsd:element name="IdAtOrigin" type="strings:IdentifierToken">
                <xsd:annotation>
                    <xsd:documentation>
                        Identifier at the source system for the dataset. 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" maxOccurs="unbounded">
                <xsd:annotation>
                    <xsd:documentation>
                        The designation of the dataset
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="Description" type="strings:MultilingualLongString" maxOccurs="unbounded">
                <xsd:annotation>
                    <xsd:documentation>
                        Explanation of the dataset
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="ArchivingInformation" type="strings:MultilingualLongString" maxOccurs="unbounded">
                <xsd:annotation>
                    <xsd:documentation>
                        Information about the archiving policy and practices for this dataset
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="Secrecy" type="strings:MultilingualLongString" maxOccurs="unbounded">
                <xsd:annotation>
                    <xsd:documentation>
                        Legal secrecy classification for the data in this dataset
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="DeletionRegulations" type="strings:MultilingualLongString" minOccurs="0" maxOccurs="unbounded">
                <xsd:annotation>
                    <xsd:documentation>
                        Regulations governing deletion of data in this dataset
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="History" type="strings:MultilingualLongString" minOccurs="0" maxOccurs="unbounded">
                <xsd:annotation>
                    <xsd:documentation>
                        Historical background of the dataset
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="Objectives" type="strings:MultilingualLongString" minOccurs="0" maxOccurs="unbounded">
                <xsd:annotation>
                    <xsd:documentation>
                        Objectives and goals of the dataset
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="PersonalData" type="enums:PersonalDataStatus">
                <xsd:annotation>
                    <xsd:documentation>
                        Indicates whether personal data exists in the dataset and its de-identification status
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="Purpose" type="strings:MultilingualLongString" minOccurs="0" maxOccurs="unbounded">
                <xsd:annotation>
                    <xsd:documentation>
                        Purpose of the dataset
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="ReferencePeriod" type="dates:DateRangeOpenEnded" minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>
                        Time period that the data refers to
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="SourceOfFunding" type="strings:MultilingualLongString" minOccurs="0" maxOccurs="unbounded">
                <xsd:annotation>
                    <xsd:documentation>
                        Funding source information
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="StatisticalDesignType" type="enums:StatisticalDesignType" minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>
                        Describes the statistical type of study for the dataset
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="Url" type="xsd:anyURI" minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>
                        URL reference to the dataset
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>

    <!-- Relations type: all relationships use EntityReference -->
    <xsd:complexType name="DatasetRelationsType">
        <xsd:sequence>
            <xsd:element name="belongsToCollection" type="strings:EntityReference" minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>
                        Reference to DatasetCollection (belongs to collection)
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>

    <!-- Main entity type -->
    <xsd:complexType name="DatasetType">
        <xsd:sequence>
            <xsd:element name="properties" type="tns:DatasetPropertiesType" minOccurs="0"/>
            <xsd:element name="relations" type="tns:DatasetRelationsType" minOccurs="0"/>
        </xsd:sequence>
    </xsd:complexType>

    <!-- Collection type -->
    <xsd:complexType name="DatasetListType">
        <xsd:sequence>
            <xsd:element name="dataset" type="tns:DatasetType" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>

    <!-- Root elements -->
    <xsd:element name="Dataset" type="tns:DatasetType"/>
    <xsd:element name="DatasetList" type="tns:DatasetListType"/>

</xsd:schema>