<?xml version="1.0"?>
<!-- Copyright (C) 2022 Intel Corporation. -->
<!-- SPDX-License-Identifier: BSD-3-Clause -->
<xs:schema xml:id="root"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:acrn="https://projectacrn.org">

  <xs:assert test="every $vm in /acrn-config/vm satisfies
                   every $vsock in $vm/virtio_devices/vsock satisfies
                   count(//virtio_devices/vsock[text()=$vsock]) = 1
                   ">
    <xs:annotation acrn:severity="error" acrn:report-on="$vm">
      <xs:documentation>VM "{$vm/name}" repeats a vsock CID assignment: {$vsock}, used in this VM or another VM. Make all vsock CID values unique.</xs:documentation>
    </xs:annotation>
  </xs:assert>

  <xs:assert test="every $vm in /acrn-config/vm[./virtio_devices/gpu[display_type = 'Full screen']] satisfies
                   $vm/virtio_devices/gpu/displays/display/monitor_id/text() != ''
                   ">
    <xs:annotation acrn:severity="error" acrn:report-on="$vm">
      <xs:documentation>VM "{$vm/name}": monitor ID is required for "full screen" virtual display.</xs:documentation>
    </xs:annotation>
  </xs:assert>

  <xs:assert test="every $vm in /acrn-config/vm[./virtio_devices/gpu[display_type = 'Window']] satisfies
                   (count($vm//window_resolutions) = count($vm//horizontal_offset)
                   and count($vm//window_resolutions) = count($vm//vertical_offset)
                   and count($vm//horizontal_offset) = count($vm//vertical_offset))
                   ">
    <xs:annotation acrn:severity="error" acrn:report-on="$vm">
      <xs:documentation>VM "{$vm/name}": every display's window resolution, horizontal offset and vertical offset are required.</xs:documentation>
    </xs:annotation>
  </xs:assert>

  <xs:assert test="every $vm in /acrn-config/vm[./virtio_devices/gpu[display_type = 'Window']] satisfies
                   $vm/virtio_devices/gpu/displays/display//window_resolutions/text() != ''
                   ">
    <xs:annotation acrn:severity="error" acrn:report-on="$vm">
      <xs:documentation>VM "{$vm/name}": window resolution is required for "window" virtual display.</xs:documentation>
    </xs:annotation>
  </xs:assert>

  <xs:assert test="every $vm in /acrn-config/vm[./virtio_devices/gpu[display_type = 'Window']] satisfies
                   $vm/virtio_devices/gpu/displays/display//horizontal_offset/text() != ''
                   ">
    <xs:annotation acrn:severity="error" acrn:report-on="$vm">
      <xs:documentation>VM "{$vm/name}": horizontal offset (pixels) is required for "window" virtual displays.</xs:documentation>
    </xs:annotation>
  </xs:assert>

    <xs:assert test="every $vm in /acrn-config/vm[./virtio_devices/gpu[display_type = 'Window']] satisfies
                     $vm/virtio_devices/gpu/displays/display//vertical_offset/text() != ''
                     ">
    <xs:annotation acrn:severity="error" acrn:report-on="$vm">
      <xs:documentation>VM "{$vm/name}": vertical offset (pixels) is required for "window" virtual displays.</xs:documentation>
    </xs:annotation>
  </xs:assert>

  <xs:assert test="every $vm in /acrn-config/vm[./virtio_devices/gpu[display_type = 'Full screen']] satisfies
                   every $monitor_id in $vm/virtio_devices/gpu/displays/display/monitor_id satisfies
                   count(//gpu[display_type = 'Full screen']//monitor_id[./text()=$monitor_id]) = 1
                   ">
    <xs:annotation acrn:severity="error" acrn:report-on="$vm">
      <xs:documentation>The monitor id "{$monitor_id}" has been assigned multiple times to VM "{$vm/name}". 
Choose a different monitor id or remove some of the virtual displays which have the same monitor id.</xs:documentation>
    </xs:annotation>
  </xs:assert>

  <xs:assert test="every $vm in /acrn-config/vm satisfies
                   count($vm/virtio_devices/gpu[display_type = 'Full screen']/displays/display) &lt; 5
                   ">
    <xs:annotation acrn:severity="error" acrn:report-on="$vm">
      <xs:documentation>VM "{$vm/name}" support 4 virtual displays at most in the full screen mode. 
Remove some of the virtual displays so that the total number does not exceed that limit.</xs:documentation>
    </xs:annotation>
  </xs:assert>

  <xs:assert test="every $vm in /acrn-config/vm satisfies
                   count($vm/virtio_devices/gpu[display_type = 'Window']/displays/display) &lt; 3
                   ">
    <xs:annotation acrn:severity="error" acrn:report-on="$vm">
      <xs:documentation>VM "{$vm/name}" support 2 virtual windows at most. 
Remove some of the virtual displays so that the total number does not exceed that limit.</xs:documentation>
    </xs:annotation>
  </xs:assert>

</xs:schema>
