openapi: 3.0.0
info:
  title: API Messagerie Sherlook
  version: 1.0.0
  description: API pour le système de messagerie de Sherlook

servers:
  - url: http://localhost:8000/api
    description: Serveur de développement

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

  schemas:
    Message:
      type: object
      properties:
        id:
          type: integer
          format: int64
        content:
          type: string
        createdAt:
          type: string
          format: date-time
        isRead:
          type: boolean
        isPicture:
          type: boolean
        author:
          $ref: '#/components/schemas/User'
        conversation:
          $ref: '#/components/schemas/Conversation'

    Conversation:
      type: object
      properties:
        id:
          type: integer
          format: int64
        createdAt:
          type: string
          format: date-time
        isPending:
          type: boolean
        author:
          $ref: '#/components/schemas/User'
        annonce:
          $ref: '#/components/schemas/Annonce'
        matching:
          $ref: '#/components/schemas/Matching'
        messages:
          type: array
          items:
            $ref: '#/components/schemas/Message'

    User:
      type: object
      properties:
        id:
          type: integer
          format: int64
        email:
          type: string
        firstName:
          type: string
        lastName:
          type: string
        picture:
          type: string
          nullable: true

    Annonce:
      type: object
      properties:
        id:
          type: integer
          format: int64
        title:
          type: string
        description:
          type: string
        status:
          type: string
          enum: [PENDING, ACCEPTED, REJECTED, DISCUSS]

    Matching:
      type: object
      properties:
        id:
          type: integer
          format: int64
        status:
          type: string
          enum: [PENDING, ACCEPTED, REJECTED, DISCUSS]
        score:
          type: number
          format: float

paths:
  /conversations:
    get:
      summary: Récupérer toutes les conversations de l'utilisateur
      security:
        - BearerAuth: []
      responses:
        '200':
          description: Liste des conversations
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Conversation'
    post:
      summary: Créer une nouvelle conversation
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - annonce
                - matching
                - messages
              properties:
                annonce:
                  type: integer
                  format: int64
                matching:
                  type: integer
                  format: int64
                messages:
                  type: array
                  items:
                    type: object
                    required:
                      - content
                    properties:
                      content:
                        type: string
                      isPicture:
                        type: boolean
                        default: false
      responses:
        '201':
          description: Conversation créée
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Conversation'

  /conversations/{id}:
    parameters:
      - name: id
        in: path
        required: true
        schema:
          type: integer
          format: int64
    get:
      summary: Récupérer une conversation spécifique
      security:
        - BearerAuth: []
      responses:
        '200':
          description: Détails de la conversation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Conversation'

  /messages:
    post:
      summary: Envoyer un nouveau message
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - conversation
                - content
              properties:
                conversation:
                  type: integer
                  format: int64
                content:
                  type: string
                isPicture:
                  type: boolean
                  default: false
      responses:
        '201':
          description: Message envoyé
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Message'

  /conversations/user:
    get:
      summary: Récupérer les conversations de l'utilisateur
      security:
        - BearerAuth: []
      responses:
        '200':
          description: Liste des conversations de l'utilisateur
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Conversation'

  /conversations/customer:
    get:
      summary: Récupérer les conversations où l'utilisateur est le client
      security:
        - BearerAuth: []
      responses:
        '200':
          description: Liste des conversations client
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Conversation' 