openapi: 3.0.3
info:
  title: GestionFerme API (Expanded)
  version: 1.0.0
  description: API backend pour l'application GestionFerme. Spécification complète avec exemples pour les endpoints principaux.
servers:
  - url: http://localhost:8080/api
    description: Serveur local (ajustez selon votre configuration)
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
  schemas:
    Bande:
      type: object
      properties:
        id: { type: integer }
        ferme_id: { type: integer }
        nb_initial: { type: integer }
        nb_mort: { type: integer }
        poids_moyen: { type: number }
        date_debut: { type: string, format: date-time }
        date_fin: { type: string, format: date-time }
    CoutProduction:
      type: object
      properties:
        id: { type: integer }
        bande_id: { type: integer }
        date_jour: { type: string, format: date }
        cout_production: { type: number, format: float }
        age_jours: { type: integer }
        note: { type: string }
      example:
        id: 1
        bande_id: 2
        date_jour: "2026-01-30"
        cout_production: 20.00
        age_jours: 35
        note: "Coût unitaire par sujet"
    Vente:
      type: object
      properties:
        id: { type: integer }
        bande_id: { type: integer }
        quantite: { type: integer }
        prix_vente: { type: number }
        montant_total: { type: number }
        date: { type: string, format: date-time }
      example:
        id: 1
        bande_id: 2
        quantite: 5
        prix_vente: 10
        montant_total: 200
        date: "2026-01-30T00:00:00"
    Benefice:
      type: object
      properties:
        id: { type: integer }
        vente_id: { type: integer }
        bande_id: { type: integer }
        date_vente: { type: string, format: date }
        montant_vente: { type: number }
        quantite: { type: integer }
        cout_production: { type: number }
        benefice: { type: number }
        note: { type: string }
      example:
        id: 1
        vente_id: 1
        bande_id: 2
        date_vente: "2026-01-30"
        montant_vente: 200.00
        quantite: 5
        cout_production: 20.00
        benefice: 100.00
        note: "Calculé automatiquement"
paths:
  /auths/login:
    post:
      summary: Authentification
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                email: { type: string }
                password: { type: string }
      responses:
        '200':
          description: Authentifié
          content:
            application/json:
              examples:
                token:
                  value: { token: "eyJhbGci..." }
  /bande/addBande:
    post:
      summary: Créer une bande
      security: [ { bearerAuth: [] } ]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Bande'
      responses:
        '201':
          description: Bande créée
          content:
            application/json:
              example: { status: 201, error: false, messages: "Bande créée", data: { id: 1 } }
  /bande/loadBande:
    get:
      summary: Lister les bandes
      security: [ { bearerAuth: [] } ]
      responses:
        '200':
          description: Liste des bandes
          content:
            application/json:
              example: { status: 200, error: false, data: [{ id: 1, ferme_id: 1, nb_initial: 100 }] }
  /bande/addCoutProduction:
    post:
      summary: Ajouter coût de production quotidien par bande (coût unitaire par sujet)
      security: [ { bearerAuth: [] } ]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CoutProduction'
      responses:
        '201':
          description: Coût enregistré
          content:
            application/json:
              example: { status: 201, error: false, messages: "Enregistré", data: { id: 1 } }
  /bande/loadCoutProduction:
    get:
      summary: Lister les coûts de production
      security: [ { bearerAuth: [] } ]
      parameters:
        - name: bande_id
          in: query
          schema: { type: integer }
      responses:
        '200':
          description: Liste des coûts
          content:
            application/json:
              example: { status: 200, error: false, data: [{ id:1, bande_id:2, date_jour: "2026-01-30", cout_production: 20.00 }] }
  /bande/showCoutProduction/{id}:
    get:
      summary: Obtenir un coût précis
      security: [ { bearerAuth: [] } ]
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
      responses:
        '200':
          description: Détail du coût
          content:
            application/json:
              example: { status: 200, error: false, data: { id:1, bande_id:2, date_jour: "2026-01-30", cout_production: 20.00 } }
  /vente/createVente:
    post:
      summary: Créer une vente
      security: [ { bearerAuth: [] } ]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Vente'
      responses:
        '201':
          description: Vente créée
          content:
            application/json:
              example: { status: 201, error: false, messages: "Enregistrement de la vente effectué avec succès", data: { id: 1 } }
  /vente/createBenefice:
    post:
      summary: Créer manuellement un enregistrement de bénéfice pour une vente
      security: [ { bearerAuth: [] } ]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Benefice'
      responses:
        '201':
          description: Benefice créé
          content:
            application/json:
              example: { status: 201, error: false, messages: "Enregistré", data: { id: 1 } }
  /vente/loadBenefice:
    get:
      summary: Lister les bénéfices
      security: [ { bearerAuth: [] } ]
      responses:
        '200':
          description: Liste des bénéfices
          content:
            application/json:
              example: { status: 200, error: false, data: [{ id:1, vente_id: 1, benefice: 100.00 }] }
  /vente/showBenefice/{id}:
    get:
      summary: Afficher un bénéfice
      security: [ { bearerAuth: [] } ]
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
      responses:
        '200':
          description: Détail du bénéfice
          content:
            application/json:
              example: { status: 200, error: false, data: { id:1, vente_id:1, montant_vente:200.00, cout_production:20.00, quantite:5, benefice:100.00 } }

  /auths/register:
    post:
      summary: Créer un utilisateur
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                email: { type: string }
                password: { type: string }
      responses:
        '201':
          description: Utilisateur créé
          content:
            application/json:
              example: { status: 201, error: false, messages: "Utilisateur créé", data: { id: 1 } }

  /auths/users:
    get:
      summary: Liste des utilisateurs (protégée)
      security: [ { bearerAuth: [] } ]
      responses:
        '200':
          description: Liste des users

  /ferme/addFerme:
    post:
      summary: Ajouter une ferme
      security: [ { bearerAuth: [] } ]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                nom: { type: string }
      responses:
        '201':
          description: Ferme créée

  /ferme/loadFerme:
    get:
      summary: Lister les fermes
      security: [ { bearerAuth: [] } ]
      responses:
        '200':
          description: Liste des fermes

  /ferme/showOneFerme/{id}:
    get:
      summary: Détails d'une ferme
      security: [ { bearerAuth: [] } ]
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
      responses:
        '200':
          description: Détails ferme

  /bande/loadBandeByFerme/{id}:
    get:
      summary: Charger les bandes d'une ferme
      security: [ { bearerAuth: [] } ]
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
      responses:
        '200':
          description: Liste des bandes

  /bande/loadBandeFerme/{id}/{id2}:
    get:
      summary: Charger les bandes d'une ferme (filtre avancé)
      security: [ { bearerAuth: [] } ]

  /bande/addMortalite:
    post:
      summary: Ajouter une mortalité
      security: [ { bearerAuth: [] } ]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                bande_id: { type: integer }
                date_mortalite: { type: string, format: date }
                nombre: { type: integer }
                cause: { type: string }
      responses:
        '201':
          description: Mortalité enregistrée

  /bande/loadMortalite:
    get:
      summary: Lister les mortalités
      security: [ { bearerAuth: [] } ]

  /aliment/addAliment:
    post:
      summary: Ajouter un aliment
      security: [ { bearerAuth: [] } ]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                libelle: { type: string }
                type: { type: string }
      responses:
        '201':
          description: Aliment créé

  /aliment/getsAliments/{id}:
    get:
      summary: Lister les aliments pour un utilisateur
      security: [ { bearerAuth: [] } ]

  /aliment/calculQuantiteAliment/{id}:
    get:
      summary: Calculer la quantité restante pour un aliment
      security: [ { bearerAuth: [] } ]

  /medicament/addMedicament:
    post:
      summary: Ajouter un médicament
      security: [ { bearerAuth: [] } ]

  /medicament/getsMedicaments/{id}:
    get:
      summary: Lister les médicaments pour un utilisateur
      security: [ { bearerAuth: [] } ]

  /medicament/getsAllMedicaments/{id}:
    get:
      summary: Lister tous les médicaments (filtré)
      security: [ { bearerAuth: [] } ]

  /medicament/calculQuantiteMedicament/{id}:
    get:
      summary: Calculer la quantité restante pour un médicament
      security: [ { bearerAuth: [] } ]

  /vente/loadVente:
    get:
      summary: Charger les ventes
      security: [ { bearerAuth: [] } ]
      responses:
        '200':
          description: Liste des ventes
          content:
            application/json:
              example: { status: 200, error: false, data: [{ id:1, bande_id:1, quantite:5, montant_total:200 }] }

security:
  - bearerAuth: []
