<?xml version="1.0" encoding="UTF-8"?>

<xs:schema version="1.0.0"
           xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:esocial="http://www.esocial.gov.br/schema/lote/eventos/envio/retornoEnvio/v1_1_0"
           targetNamespace="http://www.esocial.gov.br/schema/lote/eventos/envio/retornoEnvio/v1_1_0"
           elementFormDefault="qualified"
           attributeFormDefault="unqualified">

  <xs:element name="eSocial">
    <xs:annotation>
      <xs:documentation>Elemento raiz do eSocial.</xs:documentation>
    </xs:annotation>

    <xs:complexType>
      <xs:sequence>
        <xs:element name="retornoEnvioLoteEventos">
          <xs:annotation>
            <xs:documentation>
              Xml que contém o retorno do processo de recepção do lote de eventos.
            </xs:documentation>
          </xs:annotation>

          <xs:complexType>
            <xs:sequence>
              <xs:element name="ideEmpregador" type="esocial:TIdeEmpregador" minOccurs="0">
                <xs:annotation>
                  <xs:documentation>Identificação do empregador.</xs:documentation>
                </xs:annotation>
              </xs:element>

              <xs:element name="ideTransmissor"  type="esocial:TIdeTransmissor" minOccurs="0">
                <xs:annotation>
                  <xs:documentation>Identificação do transmissor.</xs:documentation>
                </xs:annotation>
              </xs:element>

              <xs:element name="status" type="esocial:TStatus">
                <xs:annotation>
                  <xs:documentation>Contém o status atual do lote.</xs:documentation>
                </xs:annotation>
              </xs:element>

              <xs:element name="dadosRecepcaoLote" type="esocial:TDadosRecepcao" minOccurs="0">
                <xs:annotation>
                  <xs:documentation>Contém os dados de recepção do lote.</xs:documentation>
                </xs:annotation>
              </xs:element>

            </xs:sequence>

          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:complexType name="TIdeEmpregador">
    <xs:annotation>
      <xs:documentation>Define a identificação do empregador.</xs:documentation>
    </xs:annotation>

    <xs:sequence>
      <xs:element name="tpInsc" type="xs:int"/>
      <xs:element name="nrInsc">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:maxLength value="15" />
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="TIdeTransmissor">
    <xs:annotation>
      <xs:documentation>Define a identificação do transmissor.</xs:documentation>
    </xs:annotation>

    <xs:sequence>
      <xs:element name="tpInsc" type="xs:int"/>
      <xs:element name="nrInsc">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:maxLength value="15" />
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="TDadosRecepcao">
    <xs:annotation>
      <xs:documentation>Define os dados de recepção de um arquivo (lote ou evento).</xs:documentation>
    </xs:annotation>

    <xs:sequence>
      <xs:element name="dhRecepcao" type="xs:dateTime">
        <xs:annotation>
          <xs:documentation>Data hora recepção.</xs:documentation>
        </xs:annotation>
      </xs:element>

      <xs:element name="versaoAplicativoRecepcao">
        <xs:annotation>
          <xs:documentation>Versão do aplicativo de recepção.</xs:documentation>
        </xs:annotation>

        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:maxLength value="30" />
          </xs:restriction>
        </xs:simpleType>

      </xs:element>

      <xs:element name="protocoloEnvio">
        <xs:annotation>
          <xs:documentation>
            Código de retorno para localização do lote.
            Número sequencial único produzido no instante de recepção da mensagem originada no empregador.
            São válidos os seguintes intervalos, expressos na base decimal:
            A.B.NNNNNNNNNNNNNNNNNNN
            A = Agente de recepção: Serpro=1 ou Caixa=2 (1 posição)
            B = Ambiente de recepção: Produção=1; Pré-produção - dados reais=2; Pré-produção - dados fictícios=3; Homologação=6; Validação=7; Testes=8; Desenvolvimento=9
            N = Número sequencial (19 posições)
            Exemplo:
            SERPRO: 1.1.0000000000000000001
            Caixa:  2.1.0000000000000000001

          </xs:documentation>
        </xs:annotation>

        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:maxLength value="30" />
          </xs:restriction>
        </xs:simpleType>
        
      </xs:element>

    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="TStatus">
    <xs:annotation>
      <xs:documentation>Contém o status atual do lote ou do Evento.</xs:documentation>
    </xs:annotation>

    <xs:sequence>
      <xs:element name="cdResposta" type="xs:int">
        <xs:annotation>
          <xs:documentation>
            Código de resposta da recepção do lote.
          </xs:documentation>
        </xs:annotation>
        
      </xs:element>

      <xs:element name="descResposta">
        <xs:annotation>
          <xs:documentation>Contém a descrição correspondente ao código de resposta.</xs:documentation>
        </xs:annotation>

        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:maxLength value="2048" />
          </xs:restriction>
        </xs:simpleType>

      </xs:element>

      <xs:element name="ocorrencias" type="esocial:TOcorrencias" minOccurs="0">
        <xs:annotation>
          <xs:documentation>Contém as ocorrências encontradas durante a validação do evento.</xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="TOcorrencias">
    <xs:annotation>
      <xs:documentation>Define uma ocorrência encontrada no processamento de um arquivo.</xs:documentation>
    </xs:annotation>

    <xs:sequence>
      <xs:element name="ocorrencia" minOccurs="1" maxOccurs="unbounded">
        <xs:complexType>
          <xs:sequence>
            
            <xs:element name="codigo" type="xs:int">
              <xs:annotation>
                <xs:documentation>Código da ocorrência</xs:documentation>
              </xs:annotation>
            </xs:element>

            <xs:element name="descricao">
              <xs:annotation>
                <xs:documentation>Descrição da ocorrência</xs:documentation>
              </xs:annotation>

              <xs:simpleType>
                <xs:restriction base="xs:string">
                  <xs:maxLength value="2048" />
                </xs:restriction>
              </xs:simpleType>
              
            </xs:element>

            <xs:element name="tipo" type="xs:unsignedByte">
              <xs:annotation>
                <xs:documentation>Contém o tipo da ocorrência: 1 - Erro, 2 - Advertência</xs:documentation>
              </xs:annotation>
            </xs:element>

            <xs:element name="localizacao" minOccurs="0">
              <xs:annotation>
                <xs:documentation>Contém o caminho do registro e/ou campo em que ocorreu o erro.</xs:documentation>
              </xs:annotation>

              <xs:simpleType>
                <xs:restriction base="xs:string">
                  <xs:maxLength value="2048" />
                </xs:restriction>
              </xs:simpleType>
              
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:schema>