openapi: 3.0.3
info:
  title: Smart City Martinique — Capteurs API
  description: |
    API REST mockée pour les capteurs IoT de la Martinique.
    Implémentée via Microcks pour le développement et les tests.
  version: 1.0.0
  contact:
    name: Digitribe
    url: https://digitribe.fr

servers:
  - url: https://microcks.digitribe.fr/smartcity-mock/1.0.0
    description: Microcks Mock (prod)
  - url: http://localhost:8080/smartcity-mock/1.0.0
    description: Microcks Mock (local)

paths:
  /sensors:
    get:
      operationId: getSensors
      summary: Liste de tous les capteurs
      description: Retourne la liste complète des capteurs simulés (traffic, airquality, parking, noise, weather, light)
      parameters:
        - name: type
          in: query
          schema:
            type: string
            enum: [traffic, airquality, parking, noise, weather, light]
          description: Filtrer par type de capteur
        - name: limit
          in: query
          schema:
            type: integer
            default: 50
          description: Nombre max de résultats
      responses:
        '200':
          description: Liste des capteurs
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SensorList'

  /sensors/{id}:
    get:
      operationId: getSensorById
      summary: Détail d'un capteur
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
          example: traffic_000
      responses:
        '200':
          description: Détail du capteur
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Sensor'
        '404':
          description: Capteur non trouvé

  /sensors/{id}/reading:
    get:
      operationId: getSensorReading
      summary: Dernière lecture d'un capteur
      description: Retourne la dernière valeur mesurée par le capteur
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Lecture actuelle
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SensorReading'
        '404':
          description: Capteur non trouvé

  /sensors/{id}/history:
    get:
      operationId: getSensorHistory
      summary: Historique des lectures
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
        - name: from
          in: query
          schema:
            type: string
            format: date-time
          description: Date de début (ISO 8601)
        - name: to
          in: query
          schema:
            type: string
            format: date-time
          description: Date de fin (ISO 8601)
        - name: limit
          in: query
          schema:
            type: integer
            default: 100
      responses:
        '200':
          description: Historique des lectures
          content:
            application/json:
              schema:
                type: object
                properties:
                  sensorId:
                    type: string
                  readings:
                    type: array
                    items:
                      $ref: '#/components/schemas/SensorReading'

  /traffic:
    get:
      operationId: getTrafficData
      summary: Données de trafic en temps réel
      parameters:
        - name: city
          in: query
          schema:
            type: string
            default: Fort-de-France
        - name: congestionMin
          in: query
          schema:
            type: integer
            minimum: 0
            maximum: 5
          description: Niveau de congestion minimum
      responses:
        '200':
          description: Données de trafic
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/TrafficData'

  /airquality:
    get:
      operationId: getAirQuality
      summary: Qualité de l'air — tous les capteurs
      parameters:
        - name: city
          in: query
          schema:
            type: string
            default: Fort-de-France
        - name: aqiMax
          in: query
          schema:
            type: integer
            maximum: 5
          description: AQI maximum (1=bon, 5=mauvais)
      responses:
        '200':
          description: Indices de qualité de l'air
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/AirQualityData'

  /parking:
    get:
      operationId: getParkingAvailability
      summary: Disponibilité des parkings
      responses:
        '200':
          description: État des parkings
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ParkingData'

  /weather:
    get:
      operationId: getWeather
      summary: Conditions météo actuelles
      parameters:
        - name: city
          in: query
          schema:
            type: string
            default: Fort-de-France
      responses:
        '200':
          description: Données météo
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/WeatherData'

components:
  schemas:
    Sensor:
      type: object
      required: [id, type, name, location]
      properties:
        id:
          type: string
          example: traffic_000
        type:
          type: string
          enum: [traffic, airquality, parking, noise, weather, light]
          example: traffic
        name:
          type: string
          example: Carrefour Central
        location:
          $ref: '#/components/schemas/Location'
        status:
          type: string
          enum: [active, inactive, maintenance]
          example: active
        batteryLevel:
          type: integer
          minimum: 0
          maximum: 100
          example: 85

    SensorList:
      type: object
      properties:
        count:
          type: integer
          example: 13
        sensors:
          type: array
          items:
            $ref: '#/components/schemas/Sensor'

    SensorReading:
      type: object
      properties:
        sensorId:
          type: string
        timestamp:
          type: string
          format: date-time
        value:
          type: number
        unit:
          type: string
        location:
          $ref: '#/components/schemas/Location'

    Location:
      type: object
      required: [lat, lon]
      properties:
        lat:
          type: number
          format: double
          example: 14.6091
        lon:
          type: number
          format: double
          example: -61.2155

    TrafficData:
      type: object
      properties:
        sensorId:
          type: string
        name:
          type: string
        location:
          $ref: '#/components/schemas/Location'
        vehicleCount:
          type: integer
          description: Nombre de véhicules/minute
          example: 52
        averageSpeedKmh:
          type: number
          example: 35.5
        congestionLevel:
          type: integer
          minimum: 0
          maximum: 5
          description: "0=fluide, 5=bouchon"
          example: 2
        occupancyPercent:
          type: number
          example: 65.2
        timestamp:
          type: string
          format: date-time

    AirQualityData:
      type: object
      properties:
        sensorId:
          type: string
        name:
          type: string
        location:
          $ref: '#/components/schemas/Location'
        pm25_ugm3:
          type: number
          description: PM2.5 en µg/m³
          example: 22.5
        pm10_ugm3:
          type: number
          description: PM10 en µg/m³
          example: 45.0
        no2_ugm3:
          type: number
          description: NO2 en µg/m³
          example: 18.3
        o3_ugm3:
          type: number
          description: Ozone en µg/m³
          example: 72.0
        co_mgm3:
          type: number
          description: CO en mg/m³
          example: 2.1
        temperature_celsius:
          type: number
          example: 28.5
        humidity_percent:
          type: integer
          example: 72
        aqi:
          type: integer
          minimum: 1
          maximum: 5
          description: "Air Quality Index: 1=Bon, 2=Modéré, 3=Malsain(grp sensible), 4=Malsain, 5=Très malsain"
          example: 2
        timestamp:
          type: string
          format: date-time

    ParkingData:
      type: object
      properties:
        sensorId:
          type: string
        name:
          type: string
        location:
          $ref: '#/components/schemas/Location'
        totalSpots:
          type: integer
          example: 150
        availableSpots:
          type: integer
          example: 45
        occupancyPercent:
          type: number
          example: 70.0
        turnoverPerHour:
          type: number
          description: Rotation par heure
          example: 12.5
        timestamp:
          type: string
          format: date-time

    WeatherData:
      type: object
      properties:
        sensorId:
          type: string
        name:
          type: string
        location:
          $ref: '#/components/schemas/Location'
        temperature_celsius:
          type: number
          example: 29.5
        humidity_percent:
          type: integer
          example: 78
        windSpeedKmh:
          type: number
          example: 15.3
        pressure_hpa:
          type: number
          example: 1013.2
        rain_mm:
          type: number
          description: Précipitations dernières 24h en mm
          example: 0.0
        uv:
          type: integer
          description: Indice UV (0-11+)
          example: 8
        timestamp:
          type: string
          format: date-time
