openapi: 3.0.0
info:
  title: Order Management Microservice API
  description: |
    Order processing and management microservice.
    Handles order creation, tracking, status updates, and order history.
    
    **Database**: emmanylcode_order
    **Service ID**: order-service
    **Version**: 1.0.0
  version: 1.0.0

servers:
  - url: http://localhost/projects/SMS-MICROSERVICES/order-service/public
    description: Development Order Service
  - url: https://order.emmanylcode.local
    description: Production Order Service

security:
  - BearerAuth: []

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

  schemas:
    OrderItem:
      type: object
      properties:
        product_id:
          type: integer
        quantity:
          type: integer
        price:
          type: number
          format: float

    CreateOrderRequest:
      type: object
      required:
        - user_id
        - items
        - shipping_address
      properties:
        user_id:
          type: integer
        items:
          type: array
          items:
            $ref: '#/components/schemas/OrderItem'
        shipping_address:
          type: string
        special_instructions:
          type: string

    Order:
      type: object
      properties:
        id:
          type: integer
          format: int64
        user_id:
          type: integer
        order_number:
          type: string
        total_amount:
          type: number
          format: float
        status:
          type: string
          enum: [pending, confirmed, processing, shipped, delivered, cancelled]
        items:
          type: array
          items:
            $ref: '#/components/schemas/OrderItem'
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time

paths:
  /api/orders:
    post:
      summary: Create new order
      description: Create a new order with items and shipping details
      operationId: createOrder
      tags:
        - Orders
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateOrderRequest'
      responses:
        '201':
          description: Order created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Order'
        '400':
          description: Invalid order data
        '401':
          description: Unauthorized

  /api/orders/{userId}:
    get:
      summary: Get user orders
      description: Retrieve all orders for a specific user
      operationId: getUserOrders
      tags:
        - Orders
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: integer
        - name: status
          in: query
          schema:
            type: string
      responses:
        '200':
          description: Orders retrieved
          content:
            application/json:
              schema:
                type: object
                properties:
                  orders:
                    type: array
                    items:
                      $ref: '#/components/schemas/Order'

  /api/orders/{orderId}:
    get:
      summary: Get order details
      description: Retrieve detailed information about a specific order
      operationId: getOrder
      tags:
        - Orders
      parameters:
        - name: orderId
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Order details retrieved
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Order'
        '404':
          description: Order not found

tags:
  - name: Orders
    description: Order management endpoints
