<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns:oraxdb="http://xmlns.oracle.com/xdb">
  <xs:element name="izvjestaj_sifre">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="zaglavlje" minOccurs="1" maxOccurs="1"/>
        <xs:element ref="podaci" minOccurs="1" maxOccurs="1"/>
		<!-- NOVO: Osigurava da radna vremena idu TEK NAKON podataka, 0 ili više puta -->
        <xs:element ref="podaci_rv" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="zaglavlje">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="obveznik_oib" type="oibtype"/>
        <xs:element name="datum" type="xs:date"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="podaci">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="cp_data" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="cp_data">
    <xs:complexType>
      <xs:attribute name="tip_sloga" type="tipslogatype"/>
      <xs:attribute name="sifra_cp" type="string1type"/>
      <xs:attribute name="tip_cp" type="tipcptype"/>
      <xs:attribute name="oib_ug_par" type="oibtype"/>
      <xs:attribute name="geo_sirina" type="geotype"/>
      <xs:attribute name="geo_duzina" type="geotype"/>
      <xs:attribute name="post_broj" type="postbrojtype"/>
      <xs:attribute name="mjesto" type="string2type"/>
      <xs:attribute name="ulica" type="string2type"/>
      <xs:attribute name="dod_naz_ulice" type="string2type"/>
      <xs:attribute name="kbr" type="string3type"/>
      <xs:attribute name="slovo" type="string3type"/>
      <xs:attribute name="datum_od" type="xs:date"/>
      <xs:attribute name="datum_do" type="xs:date"/>
	  <!-- NOVO: Četiri nova atributa na razini pojedinačnog cp_data sloga, eksplicitno navedeno da su  -->
      <!-- opcionalni (to vrijedi, implicitno, i za ostale iznad navedene). -->
      <xs:attribute name="vrsta_poslovnice" type="string4type" use="optional"/>
      <xs:attribute name="sezonalnost_uredaja" type="string5type" use="optional"/>
      <xs:attribute name="tip_lokacije" type="string6type" use="optional"/>
	  <xs:attribute name="specificna_lokacija" type="string7type" use="optional"/>
    </xs:complexType>
  </xs:element>
  
  <xs:element name="podaci_rv">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="dan" minOccurs="0" maxOccurs="8">
          <xs:complexType>
            <xs:sequence>
              <!-- Promijenjen tip u nazivDanatype radi kontrole unosa (npr. PON-PET) -->
              <xs:element name="naziv_dana" type="nazivDanatype"/>
              <!-- xs:choice omogućuje ILI unos smjena ILI opisni tekst -->
              <xs:choice>
                <!-- Opcija A: Standardne smjene (višekratno radno vrijeme) -->
                <xs:element name="smjena" minOccurs="1" maxOccurs="unbounded">
                  <xs:complexType>
                    <xs:sequence>
                      <xs:element name="radno_od" type="vrijemetype"/>
                      <xs:element name="radno_do" type="vrijemetype"/>
                    </xs:sequence>
                  </xs:complexType>
                </xs:element>
                <!-- Opcija B: Slobodan ili poluslobodan tekst (npr. "ne radi se") -->
                <xs:element name="status_tekst" type="statusTeksttype"/>
              </xs:choice>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <!-- Atributi poslovnice (XSD pravilo: pišu se na kraju tipa, u XML-u su na vrhu) -->
      <xs:attribute name="tip_sloga" type="tipslogarvtype" use="required"/> <!-- NOVO: tip '5' -->
      <xs:attribute name="sifra_cp" type="string1type" use="required"/>
	  <!-- U nekom trenutku tip_cp je maknut iz ovog dodatnog sloga (što je OK, tu nije nužan) -->
      <!-- <xs:attribute name="tip_cp" type="tipcptype" use="required"/> -->
      <xs:attribute name="oib_ug_par" type="oibtype" use="required"/>
	  <xs:attribute name="datum_od" type="xs:date"/>
    </xs:complexType>
  </xs:element>

  <xs:simpleType name="oibtype">
    <xs:restriction base="xs:string">
      <xs:pattern value="\d{11}"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="string1type">
    <xs:restriction base="xs:string">
      <xs:minLength value="1"/>
      <xs:maxLength value="50"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="string2type">
    <xs:restriction base="xs:string">
      <xs:minLength value="0"/>
      <xs:maxLength value="255"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="string3type">
    <xs:restriction base="xs:string">
      <xs:minLength value="0"/>
      <xs:maxLength value="25"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="string4type">
    <xs:restriction base="xs:string">
      <xs:pattern value="P|B|T|N"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="string5type">
    <xs:restriction base="xs:string">
      <xs:pattern value="S|C|SR|CR"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="string6type">
    <xs:restriction base="xs:string">
      <xs:pattern value="PJ|ZP|OP"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="string7type">
    <xs:restriction base="xs:string">
      <xs:pattern value="DA|NE"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="postbrojtype">
    <xs:restriction base="xs:string">
      <xs:pattern value="\d{5}"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="tipcptype">
    <xs:restriction base="xs:string">
      <xs:pattern value="1|2|3|4"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="tipslogatype">
    <xs:restriction base="xs:string">
      <xs:pattern value="1|2|3|4"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="geotype">
    <xs:restriction base="xs:string">
      <xs:pattern value="\d{1,3}\.\d{6}\d{0,6}"/>
    </xs:restriction>
  </xs:simpleType>
  <!-- NOVO: tip_sloga za radno vrijeme smije biti isključivo broj 5 -->
  <xs:simpleType name="tipslogarvtype">
    <xs:restriction base="xs:string">
      <xs:pattern value="5"/>
    </xs:restriction>
  </xs:simpleType>
  <!-- NOVI TIP: Definira dopuštene kratice i raspone (npr. PON, PON-PET, PRAZNIK) -->
  <xs:simpleType name="nazivDanatype">
    <xs:restriction base="xs:string">
      <!-- Pattern dopušta pojedinačne dane ILI dva dana spojena crticom -->
      <xs:pattern value="(PON|UTO|SRI|CET|PET|SUB|NED|PRAZNIK)(-(PON|UTO|SRI|CET|PET|SUB|NED|PRAZNIK))?"/>
    </xs:restriction>
  </xs:simpleType>
  <!-- NOVI TIP: Ograničava opisni tekst (na maksimalno 100 znakova) -->
  <xs:simpleType name="statusTeksttype">
    <xs:restriction base="xs:string">
      <xs:minLength value="1"/>
      <xs:maxLength value="100"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="vrijemetype">
    <xs:restriction base="xs:string">
      <xs:pattern value="([0-1][0-9]|2[0-3]):[0-5][0-9]"/>
    </xs:restriction>
  </xs:simpleType>

</xs:schema>
