openapi: 3.0.3
info:
  title: GoPaaS API
  version: 1.0.0
  description: API GoPaaS

servers:
  - url: https://your-domain.tld

tags:
  - name: Authentication
  - name: List
  - name: Item
  - name: Items
  - name: File

paths:
  /api/authenticate/:
    get:
      tags: [Authentication]
      summary: Obtenir un token d'authentification
      description: Authentification Basic en Base64 au format `login:password`.
      parameters:
        - in: header
          name: Authorization
          required: true
          schema:
            type: string
            example: Basic bG9naW46cGFzc3dvcmQ=
          description: Header Basic Base64
      responses:
        '200':
          description: Token généré
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthTokenResponse'
        '401':
          description: Identifiants invalides
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorInvalidCredentials'
        '500':
          description: Erreur serveur
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorServer'
    post:
      tags: [Authentication]
      summary: Obtenir un token d'authentification
      description: Authentification Basic en Base64 au format `login:password`.
      parameters:
        - in: header
          name: Authorization
          required: true
          schema:
            type: string
            example: Basic bG9naW46cGFzc3dvcmQ=
          description: Header Basic Base64
      responses:
        '200':
          description: Token généré
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthTokenResponse'
        '401':
          description: Identifiants invalides
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorInvalidCredentials'
        '500':
          description: Erreur serveur
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorServer'

  /api/list/{id}/:
    get:
      tags: [List]
      summary: Récupérer la liste des fiches d'une vue
      security:
        - bearerAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Identifiant unique de la vue
        - in: header
          name: advancedSearch
          required: false
          schema:
            type: string
            example: nom|contain|NIDS|AND|cp|contain|77420|
          description: Recherche avancée sur une ou plusieurs colonnes
        - in: header
          name: textSearch
          required: false
          schema:
            type: string
          description: Recherche textuelle sur les colonnes
        - in: header
          name: onlyVisible
          required: false
          schema:
            type: string
            example: on
          description: Masquer les colonnes non visibles
        - in: header
          name: columns
          required: false
          schema:
            type: string
            example: on
          description: Ajouter l'objet column dans la réponse
        - in: header
          name: page
          required: false
          schema:
            type: integer
            example: 3
          description: Numéro de page
        - in: header
          name: rowPerPage
          required: false
          schema:
            type: integer
            example: 10
          description: Nombre de fiches par page
      responses:
        '200':
          description: Liste récupérée
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenericObject'
        '400':
          description: Version invalide
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorInvalidVersion'
        '401':
          description: Clé API invalide
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorInvalidApiKey'
        '500':
          description: Erreur serveur
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorServer'

  /api/item/{tableName}/{id}/:
    get:
      tags: [Item]
      summary: Récupérer une fiche
      security:
        - bearerAuth: []
      parameters:
        - in: path
          name: tableName
          required: true
          schema:
            type: string
          description: Nom de la table
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Identifiant unique de la fiche
      responses:
        '200':
          description: Fiche récupérée
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenericObject'
        '400':
          description: Version invalide
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorInvalidVersion'
        '401':
          description: Clé API invalide
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorInvalidApiKey'
        '500':
          description: Erreur serveur
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorServer'

  /api/items/{tableName}/:
    post:
      tags: [Items]
      summary: Créer ou mettre à jour plusieurs fiches
      description: |
        Permet de créer ou mettre à jour plusieurs fiches.
        Supporte également l'upload de fichiers encodés en Base64 via la propriété `files`.
      security:
        - bearerAuth: []
      parameters:
        - in: path
          name: tableName
          required: true
          schema:
            type: string
          description: Nom de la table
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/ItemsRequestItem'
            examples:
              simple:
                summary: Insertion simple
                value:
                  - cle: KEY001
                    num_commande: "551035"
                    date_billed: "2016-07-05"
                    actual_billable_amount: "437.50"
                    num_invoice: "16000162"
                    date_closed: "2016-09-05"
                  - cle: KEY002
                    num_commande: "672620"
                    date_billed: "2017-06-14"
                    actual_billable_amount: "595"
                    num_invoice: "17000100"
                    date_closed: "2017-07-31"
              withFiles:
                summary: Insertion avec fichiers Base64
                value:
                  - cle: KEY003
                    num_commande: "551035"
                    num_invoice: "16000162"
                    files:
                      - fieldName: fichier
                        fileName: facture_16000162.pdf
                        base64: JVBERi0xLjQKJeLjz9MKMSAwIG9iago...
      responses:
        '200':
          description: Traitement effectué
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenericObject'
        '400':
          description: Version invalide
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorInvalidVersion'
        '401':
          description: Clé API invalide
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorInvalidApiKey'
        '500':
          description: Erreur serveur
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorServer'

  /api/file/{tableName}/:
    post:
      tags: [File]
      summary: Upload d'un fichier
      security:
        - bearerAuth: []
      parameters:
        - in: path
          name: tableName
          required: true
          schema:
            type: string
          description: Nom de la table
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - file
              properties:
                file:
                  type: string
                  format: binary
      responses:
        '200':
          description: Fichier uploadé
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenericObject'
        '400':
          description: Version invalide
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorInvalidVersion'
        '401':
          description: Clé API invalide
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorInvalidApiKey'
        '500':
          description: Erreur serveur
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorServer'

  /api/filebase64/{tableName}/:
    post:
      tags: [File]
      summary: Upload d'un fichier Base64
      description: Uploade un fichier encodé en Base64 et l'assigne à un champ spécifique d'une fiche.
      security:
        - bearerAuth: []
      parameters:
        - in: path
          name: tableName
          required: true
          schema:
            type: string
          description: Nom de la table
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/FileBase64RequestItem'
            example:
              - cle: test_NIDS
                intitule: FC2025-145358
                files:
                  - fieldName: fichier
                    fileName: 2025-03-31_FC2025-145358.pdf
                    base64: JVBERi0xLjQKJeLjz9MKMSAwIG9iago...
      responses:
        '200':
          description: Fichier traité
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenericObject'
        '400':
          description: Version invalide
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorInvalidVersion'
        '401':
          description: Clé API invalide
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorInvalidApiKey'
        '500':
          description: Erreur serveur
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorServer'

components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

  schemas:
    AuthTokenResponse:
      type: object
      properties:
        token:
          type: string
          example: ezjidsojd....
      required:
        - token

    ErrorInvalidVersion:
      type: object
      properties:
        msg:
          type: string
          example: Invalid version.

    ErrorInvalidApiKey:
      type: object
      properties:
        msg:
          type: string
          example: Invalid API key.

    ErrorInvalidCredentials:
      type: object
      properties:
        msg:
          type: string
          example: Invalid credentials

    ErrorServer:
      type: object
      properties:
        msg:
          type: string
          example: Something went wrong. Please try again later.

    GenericObject:
      type: object
      additionalProperties: true

    FileObject:
      type: object
      properties:
        fieldName:
          type: string
          example: fichier
        fileName:
          type: string
          example: facture.pdf
        base64:
          type: string
          example: JVBERi0xLjQKJeLjz9MKMSAwIG9iago...
      required:
        - fieldName
        - fileName
        - base64

    ItemsRequestItem:
      type: object
      description: Objet libre représentant une fiche GoPaaS
      properties:
        files:
          type: array
          items:
            $ref: '#/components/schemas/FileObject'
      additionalProperties: true

    FileBase64RequestItem:
      type: object
      properties:
        cle:
          type: string
          example: test_NIDS
        intitule:
          type: string
          example: FC2025-145358
        files:
          type: array
          items:
            $ref: '#/components/schemas/FileObject'
      required:
        - files
      additionalProperties: true