openapi: 3.0.0
security:
  - BearerAuth: []

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

tags:
  - name: Reviews
    description: API endpoints for managing reviews

paths:
  /api/reviews:
    get:
      summary: Get all reviews
      tags: [Reviews]
      security:
        - BearerAuth: []
      responses:
        200:
          description: A list of reviews
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      reviews:
                        type: array
                        items:
                          type: object
                          properties:
                            id:
                              type: string
                              example: "123e4567-e89b-12d3-a456-426614174000"
                            userId:
                              type: string
                              example: "123e4567-e89b-12d3-a456-426614174000"
                            rating:
                              type: integer
                              minimum: 1
                              maximum: 5
                              example: 5
                            comment:
                              type: string
                              example: "Great food and service!"
                            createdAt:
                              type: string
                              format: date-time
                            updatedAt:
                              type: string
                              format: date-time
                            user:
                              type: object
                              properties:
                                id:
                                  type: string
                                name:
                                  type: string
                                email:
                                  type: string
        404:
          description: No reviews found
        401:
          description: Unauthorized
        500:
          description: Internal server error
    post:
      summary: Create a new review
      tags: [Reviews]
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - rating
              properties:
                rating:
                  type: integer
                  minimum: 1
                  maximum: 5
                  example: 5
                  description: Rating from 1 to 5
                comment:
                  type: string
                  example: "Great food and service!"
                  description: Optional comment about the review
      responses:
        201:
          description: Review created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      review:
                        type: object
                        properties:
                          id:
                            type: string
                          userId:
                            type: string
                          rating:
                            type: integer
                          comment:
                            type: string
                          createdAt:
                            type: string
                            format: date-time
                          updatedAt:
                            type: string
                            format: date-time
                          user:
                            type: object
        400:
          description: Bad request (invalid rating or review already exists)
        401:
          description: Unauthorized
        500:
          description: Internal server error

  /api/reviews/me:
    get:
      summary: Get my review
      tags: [Reviews]
      security:
        - BearerAuth: []
      responses:
        200:
          description: User's review
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      review:
                        type: object
                        properties:
                          id:
                            type: string
                          userId:
                            type: string
                          rating:
                            type: integer
                          comment:
                            type: string
                          createdAt:
                            type: string
                            format: date-time
                          updatedAt:
                            type: string
                            format: date-time
                          user:
                            type: object
        404:
          description: Review not found
        401:
          description: Unauthorized
        500:
          description: Internal server error
    put:
      summary: Update my review
      tags: [Reviews]
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                rating:
                  type: integer
                  minimum: 1
                  maximum: 5
                  example: 4
                  description: Updated rating from 1 to 5
                comment:
                  type: string
                  example: "Updated comment about the service"
                  description: Updated comment about the review
      responses:
        200:
          description: Review updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      review:
                        type: object
                        properties:
                          id:
                            type: string
                          userId:
                            type: string
                          rating:
                            type: integer
                          comment:
                            type: string
                          createdAt:
                            type: string
                            format: date-time
                          updatedAt:
                            type: string
                            format: date-time
                          user:
                            type: object
        400:
          description: Bad request (invalid rating)
        401:
          description: Unauthorized
        404:
          description: Review not found
        500:
          description: Internal server error

