openapi: 3.0.3
info:
  title: NOALYSS Peppol API
  description: >
    API pour interagir avec le réseau PEPPOL via NOALYSS.
    Permet de lister les documents entrants/sortants, d'envoyer des documents,
    de valider des XML PEPPOL et de récupérer le contenu d'un document par son ID.
  version: 1.0
  contact:
    name: Support NOALYSS
    url: https://noalyss.eu

servers:
  - url: http://localhost/developpement/peppol/script-PEPPOL/web/index.php
    description: Serveur local de développement

components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: Opaque
      description: Bearer token obtenu après authentification avec l'utilisateur

    authzX:
      type: apiKey
      in: header
      name: AUTHZ-X
      description: >
        Token d'authentification opaque envoyé dans le header personnalisé AUTHZ-X.
        Format attendu : Noalyss-Authz: <votre-token-opaque>

  schemas:
    DocumentListItem:
      type: object
      required:
        - uuid
      properties:
        uuid:
          type: string
          format: uuid
        date_received:
          type: string
          format: date-time
          nullable: false
        date_document:
          type: string
          format: date
          nullable: false
        senderPeppolId:
          type: string
          nullable: true
        receiverPeppolId:
          type: string
          nullable: true
        status:
          type: string
          nullable: true

    UserInfo:
      type: object
      properties:
        transfer:
          type: string
        peppol_id:
          type: string
          description: peppol_id du client
        remain_doc:
          type: number
          description: nombre de documents restants dans la réserve
        consumed_doc:
          type: number
          description: nombre de documents envoyés ou reçus
        autorization:
          type: string
          description: token d'authentification, valable 20 minutes

    ValidationResult:
      type: object
      required:
        - status
      properties:
        status:
          type: string
          enum: [valid, invalid]
        errors:
          type: array
          items:
            type: object
            required:
              - code
              - message
            properties:
              code:
                type: string
              message:
                type: string

    SendResponse:
      type: object
      required:
        - id
        - status
      properties:
        id:
          type: string
          format: uuid
        status:
          type: string
          enum: [queued, sent, validation_failed, failed]
        message:
          type: string
          nullable: true

paths:

  /cnx:
    post:
      summary: Connexion pour les instances NOALYSS hébergées
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [participantId]
              properties:
                participantId:
                  type: string
                  description: Identifiant PEPPOL (participant ID)
      responses:
        '200':
          description: Connexion réussie
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/UserInfo"
        '401':
          description: Echec authentification

  /documents/incoming:
    get:
      summary: Lister les documents entrants
      operationId: getIncomingDocuments
      security:
        - bearerAuth: []
      parameters:
        - name: format
          in: query
          required: true
          schema:
            type: string
            enum: [full, list]
        - name: max_file
          in: query
          schema:
            type: integer
      responses:
        '200':
          description: Liste des documents (UUID uniquement ou complet)
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/DocumentListItem'

  /documents/outgoing:
    post:
      summary: Envoie un document
      operationId: sendOutgoingDocument
      security:
        - bearerAuth: []
      parameters:
        - name: AUTHZ
          in: header
          required: true
          schema:
            type: string
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                file:
                  type: object
                param:
                  type: object
                  properties:
                    uuid:
                      type: string
                      format: uuid
                    email:
                      type: string
                      format: email
                  description: send embedding documents by email, emails separated by comma
      responses:
        '200':
          description: Document queued
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/DocumentListItem'

  /documents/{documentId}:
    get:
      summary: Récupérer le contenu d'un document
      description: Retourne le document original (généralement UBL/XML PEPPOL)
      operationId: getDocumentById
      security:
        - bearerAuth: []
      parameters:
        - name: documentId
          in: path
          required: true
          schema:
            type: string
        - name: dir
          in: query
          required: false
          schema:
            type: string
            enum: [in, out]
        - name: format
          in: query
          required: false
          schema:
            type: string
            enum: [full, info]
      responses:
        '200':
          description: renvoie un Document
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DocumentListItem'

  /validate:
    post:
      summary: Valider un document PEPPOL sans l'envoyer
      operationId: validateDocument
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/xml:
            schema:
              type: string
              format: binary
      responses:
        '200':
          description: Résultat de la validation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationResult'
