openapi: 3.0.3
info:
  title: Carrier API
  version: 1.0.0
  description: |
    The API has been designed to allow partners of Super Dispatch to share information back and forth between two [or more] systems.
    Our RESTful API allows an order to be sent through Super Dispatch, to be fulfilled using Super Dispatch's Mobile app and Dashboard [TMS],
    while allowing other [select] systems to receive requested updates during the order's lifecycle.

    ## Key Features
    - Send order to a carrier via Super Dispatch mobile application
    - Receive a confirmation
    - Vehicle inspection
    - Order tracking
    - Proof of delivery (ePOD)
    - Bill of lading (eBOL)

    ## Requirements
    - Use only `https` connection
    - We use REST for communications
    - We use Webhook to notify about order status updates
    - For all requests and responses we use `application/json` as a content type
    - Cross-origin resource sharing is enabled by default
    - We DO NOT recommend long-polling the API. The API is rate limited

    ## Terminology
    - **Broker**: An intermediary who arranges transactions between a buyer and a seller
    - **Carrier**: A transportation company that owns one or multiple trucks
    - **Owner Operator**: A company/professional who owns and operates their business with a single truck
    - **Fleet**: A company that runs and manages a group of trucks
    - **Driver**: A truck driver who is responsible for shipping vehicles
    - **Vehicle**: A single vehicle (usually associated with a specific VIN)
    - **BOL (Bill of Lading)**: A document that describes inspection details of a particular vehicle

    ## Order States
    - **Unassigned**: An order is not assigned to a driver
    - **Assigned**: An order is assigned to a driver
    - **Picked Up**: An order is picked up by a driver from an origin
    - **In Transit**: An order is on its way
    - **Delivered**: An order is delivered by a driver to a destination
    - **Archived**: An order is archived
    - **Billed**: An order has been invoiced to a customer
    - **Paid**: A payment for the order has been received by a customer
  contact:
    name: API Support
    url: https://developer.superdispatch.com
    email: support@superdispatch.com
  x-postman-collection: https://www.postman.com/superdispatch/workspace/superdispatch-public-api

servers:
  - url: https://carrier.superdispatch.com/v1
    description: Production Environment
  - url: https://staging.carrier.superdispatch.org/v1
    description: Staging Environment

security:
  - oauth2: []

tags:
  - name: Authentication
    description: OAuth 2.0 authentication endpoints
  - name: Carriers
    description: Carrier management endpoints
  - name: Drivers
    description: Driver management endpoints
  - name: Orders
    description: Order management endpoints
  - name: Order Attachments
    description: Order attachment endpoints
  - name: Vehicles
    description: Vehicle management endpoints
  - name: Expenses
    description: Expense tracking endpoints
  - name: Invoices
    description: Invoice endpoints
  - name: Offers
    description: Offer management endpoints
  - name: Inspection Photos
    description: Vehicle inspection photo endpoints
  - name: Damages
    description: Vehicle damage reporting endpoints
  - name: Inspections
    description: Vehicle inspection endpoints
  - name: Signatures
    description: Digital signature endpoints
  - name: Webhooks
    description: Webhook subscription management endpoints

components:
  securitySchemes:
    oauth2:
      type: oauth2
      flows:
        clientCredentials:
          tokenUrl: /oauth/token/
          scopes:
            carrier: Carrier operations
            driver: Driver operations
            expense: Expense operations
            invoice: Invoice operations
            order: Order operations
            webhook: Webhook operations
      description: |
        The API supports OAuth 2 Client Credentials grant type. Get `access_token` by sending an authentication request with `client_id` and `client_secret`.

  parameters:
    carrier_id:
      name: id
      in: path
      required: true
      description: Carrier ID
      schema:
        type: integer

    driver_id:
      name: id
      in: path
      required: true
      description: Driver ID
      schema:
        type: integer

    order_id:
      name: id
      in: path
      required: true
      description: Order ID
      schema:
        type: integer

    vehicle_id:
      name: id
      in: path
      required: true
      description: Vehicle ID
      schema:
        type: integer

    attachment_id:
      name: id
      in: path
      required: true
      description: Attachment ID
      schema:
        type: integer

    expense_id:
      name: id
      in: path
      required: true
      description: Expense ID
      schema:
        type: integer

    invoice_id:
      name: id
      in: path
      required: true
      description: Invoice ID
      schema:
        type: integer

    offer_id:
      name: id
      in: path
      required: true
      description: Offer ID
      schema:
        type: integer

    photo_id:
      name: id
      in: path
      required: true
      description: Photo ID
      schema:
        type: integer

    damage_id:
      name: id
      in: path
      required: true
      description: Damage ID
      schema:
        type: integer

    inspection_id:
      name: id
      in: path
      required: true
      description: Inspection ID
      schema:
        type: integer

    per_page:
      name: per_page
      in: query
      description: Number of items per page
      schema:
        type: integer
        default: 20
        maximum: 100

    page:
      name: page
      in: query
      description: Page number
      schema:
        type: integer
        default: 1

  schemas:
    Meta:
      type: object
      description: Response metadata
      properties:
        code:
          type: integer
          description: HTTP Status Code
          example: 200
        request_id:
          type: string
          description: Request ID generated for each request by the API
          example: "req_abc123xyz"
      required:
        - code
        - request_id

    Pagination:
      type: object
      description: Pagination information
      properties:
        previous:
          type: string
          nullable: true
          description: A link to request for previous items
          example: "https://carrier.superdispatch.com/v1/orders/?page=1"
        next:
          type: string
          nullable: true
          description: A link to request for next items
          example: "https://carrier.superdispatch.com/v1/orders/?page=3"
        total:
          type: integer
          description: Total number of items
          example: 150

    ErrorResponse:
      type: object
      properties:
        meta:
          $ref: "#/components/schemas/Meta"
        error:
          type: object
          properties:
            message:
              type: string
              description: Human-readable error message
            context:
              type: object
              description: Field-level validation errors (key = field name, value = list of messages)
              additionalProperties:
                type: array
                items:
                  type: string

    # Carrier Schemas
    Carrier:
      type: object
      properties:
        id:
          type: integer
          description: Super Dispatch Carrier ID
          example: 67890
        name:
          type: string
          description: Carrier name
          example: "Fast Transport LLC"
        mc_number:
          type: string
          nullable: true
          description: Motor Carrier number
        us_dot_number:
          type: string
          nullable: true
          description: US DOT number
        address:
          type: string
          nullable: true
          description: Street address
        city:
          type: string
          nullable: true
          description: City
        state:
          type: string
          nullable: true
          description: State code
        zip:
          type: string
          nullable: true
          description: ZIP code
        guid:
          type: string
          format: uuid
          description: Carrier UUID
        number_of_trucks:
          type: integer
          nullable: true
          description: Number of trucks in the carrier fleet
        contact:
          type: object
          properties:
            name:
              type: string
              nullable: true
            phone:
              type: string
              nullable: true
            email:
              type: string
              format: email
              nullable: true
            fax:
              type: string
              nullable: true
        created_at:
          type: string
          format: date-time
          description: Timestamp when carrier was created

    # Driver Schemas
    DriverBase:
      type: object
      properties:
        name:
          type: string
          description: Name of the driver
          example: "John Doe"
        email:
          type: string
          format: email
          description: Email address of the driver
          example: "john.doe@example.com"
        phone:
          type: string
          description: Phone number of the driver
          example: "+1234567890"
        truck_capacity:
          type: integer
          description: Truck capacity
          example: 8
      required:
        - name
        - email
        - phone
        - truck_capacity

    Driver:
      allOf:
        - $ref: "#/components/schemas/DriverBase"
        - type: object
          properties:
            id:
              type: integer
              description: Super Dispatch Driver ID
              example: 12345
            carrier_id:
              type: integer
              description: Carrier ID the driver belongs to
              example: 67890
            status:
              type: string
              enum: [pending, activated, deactivated]
              description: Driver status
              example: "activated"
            created_at:
              type: string
              format: date-time
              description: Timestamp when driver was created
            updated_at:
              type: string
              format: date-time
              description: Timestamp when driver was last updated

    DriverLocation:
      type: object
      properties:
        driver_id:
          type: integer
          description: Driver ID
        latitude:
          type: number
          format: double
          description: Latitude coordinate
          example: 40.7128
        longitude:
          type: number
          format: double
          description: Longitude coordinate
          example: -74.0060
        updated_at:
          type: string
          format: date-time
          description: Timestamp when location was last updated

    # Order Schemas
    Venue:
      type: object
      description: Location details for pickup or delivery
      properties:
        name:
          type: string
          nullable: true
          description: Venue name
        address:
          type: string
          nullable: true
          description: Street address
        city:
          type: string
          nullable: true
          description: City
        state:
          type: string
          nullable: true
          description: State code
        zip:
          type: string
          nullable: true
          description: ZIP code
        notes:
          type: string
          nullable: true
          description: Additional notes for the venue
        contact:
          $ref: "#/components/schemas/Contact"

    Address:
      type: object
      properties:
        city:
          type: string
          description: City name
          example: "New York"
        state:
          type: string
          description: State code
          example: "NY"
        zip:
          type: string
          description: ZIP code
          example: "10001"
        street:
          type: string
          description: Street address
          example: "123 Main St"
        latitude:
          type: number
          format: double
          nullable: true
          description: Latitude coordinate
        longitude:
          type: number
          format: double
          nullable: true
          description: Longitude coordinate

    Contact:
      type: object
      properties:
        name:
          type: string
          description: Contact name
          example: "Jane Smith"
        phone:
          type: string
          description: Contact phone number
          example: "+1987654321"
        phone2:
          type: string
          nullable: true
          description: Secondary phone number
        email:
          type: string
          format: email
          nullable: true
          description: Contact email address
        company_name:
          type: string
          nullable: true
          description: Company name
      required:
        - name
        - phone

    VehicleInfo:
      type: object
      properties:
        year:
          type: integer
          description: Vehicle year
          example: 2020
        make:
          type: string
          description: Vehicle make
          example: "Tesla"
        model:
          type: string
          description: Vehicle model
          example: "Model 3"
        vin:
          type: string
          description: Vehicle identification number
          example: "5YJ3E1EA1LF123456"
        type:
          type: string
          enum:
            [sedan, suv, truck, van, motorcycle, boat, atv, rv, trailer, other]
          description: Vehicle type
        color:
          type: string
          nullable: true
          description: Vehicle color
        lot_number:
          type: string
          nullable: true
          description: Lot number
        is_inoperable:
          type: boolean
          default: false
          description: Whether the vehicle is inoperable
        requires_enclosed_trailer:
          type: boolean
          default: false
          description: Whether the vehicle requires an enclosed trailer
        price:
          type: number
          format: decimal
          nullable: true
          description: Per-vehicle price
      required:
        - year
        - make
        - model

    OrderStop:
      type: object
      description: Pickup or delivery stop
      properties:
        venue:
          $ref: "#/components/schemas/Venue"
        scheduled_at:
          type: string
          format: date
          nullable: true
          description: Scheduled date
        completed_at:
          type: string
          format: date-time
          nullable: true
          description: Actual completion timestamp
        notes:
          type: string
          nullable: true
          description: Stop-level notes

    OrderPayment:
      type: object
      description: Payment details for the order
      properties:
        terms:
          type: string
          nullable: true
          description: Payment terms
        notes:
          type: string
          nullable: true
        payment_method:
          type: string
          nullable: true
          description: Payment method
        payment_terms:
          type: string
          nullable: true
          description: Payment terms type (e.g. quick_pay)

    OrderCustomer:
      type: object
      description: Customer details
      properties:
        name:
          type: string
          nullable: true
        address:
          type: string
          nullable: true
        city:
          type: string
          nullable: true
        state:
          type: string
          nullable: true
        zip:
          type: string
          nullable: true
        contact:
          $ref: "#/components/schemas/Contact"

    OrderBase:
      type: object
      properties:
        number:
          type: string
          nullable: true
          description: Order number / reference
        price:
          type: number
          format: decimal
          description: Carrier pay amount
          example: 750.00
        buyer_number:
          type: string
          nullable: true
          description: Buyer reference number
        broker_fee:
          type: number
          format: decimal
          nullable: true
          description: Broker fee amount
        instructions:
          type: string
          nullable: true
          description: Special instructions
        inspection_type:
          type: string
          nullable: true
          description: Inspection type (e.g. standard, aiag)
        driver_id:
          type: integer
          nullable: true
          description: ID of driver to assign at creation
        payment:
          $ref: "#/components/schemas/OrderPayment"
        customer:
          $ref: "#/components/schemas/OrderCustomer"
        pickup:
          $ref: "#/components/schemas/OrderStop"
        delivery:
          $ref: "#/components/schemas/OrderStop"
        vehicles:
          type: array
          items:
            $ref: "#/components/schemas/VehicleInfo"
          description: List of vehicles in the order
      required:
        - price
        - pickup
        - delivery
        - vehicles

    Order:
      allOf:
        - $ref: "#/components/schemas/OrderBase"
        - type: object
          properties:
            id:
              type: integer
              description: Super Dispatch Order ID
              example: 54321
            status:
              type: string
              enum:
                [
                  new,
                  unassigned,
                  assigned,
                  picked_up,
                  in_transit,
                  delivered,
                  archived,
                  billed,
                  paid,
                ]
              description: Order status
            carrier_name:
              type: string
              nullable: true
              description: Name of the carrier
            is_canceled:
              type: boolean
              description: Whether the order has been canceled
            pdf_bol_url:
              type: string
              format: uri
              nullable: true
              description: URL to the PDF Bill of Lading
            internal_notes:
              type: array
              items:
                type: object
              description: Internal notes on the order
            created_at:
              type: string
              format: date-time
              description: Timestamp when order was created
            updated_at:
              type: string
              format: date-time
              description: Timestamp when order was last updated
            picked_up_at:
              type: string
              format: date-time
              nullable: true
              description: Timestamp when order was picked up
            delivered_at:
              type: string
              format: date-time
              nullable: true
              description: Timestamp when order was delivered

    # Vehicle Schemas
    Vehicle:
      allOf:
        - $ref: "#/components/schemas/VehicleInfo"
        - type: object
          properties:
            id:
              type: integer
              description: Super Dispatch Vehicle ID
              example: 98765
            order_id:
              type: integer
              description: Order ID the vehicle belongs to
            created_at:
              type: string
              format: date-time
              description: Timestamp when vehicle was created
            updated_at:
              type: string
              format: date-time
              description: Timestamp when vehicle was last updated

    # Attachment Schemas
    Attachment:
      type: object
      properties:
        id:
          type: integer
          description: Attachment ID
          example: 11111
        name:
          type: string
          description: File name
          example: "invoice.pdf"
        url:
          type: string
          format: uri
          description: URL to download the file

    # Expense Schemas
    Expense:
      type: object
      properties:
        id:
          type: integer
          description: Expense ID
          example: 22222
        order_id:
          type: integer
          description: Order ID the expense belongs to
        price:
          type: number
          format: decimal
          description: Expense amount (negative values represent deductions)
          example: -150.00
        type:
          type: string
          nullable: true
          description: Expense type/category (e.g. fuel, other)
        name_for_type_other:
          type: string
          nullable: true
          description: Custom name when type is "other"
        receipt_date:
          type: string
          format: date-time
          nullable: true
          description: Date of the receipt
        show_on_invoice:
          type: boolean
          nullable: true
          description: Whether to show this expense on the invoice
        deduct_from_driver_pay:
          type: boolean
          nullable: true
          description: Whether to deduct this expense from driver pay
        created_at:
          type: string
          format: date-time
          description: Timestamp when expense was created
      required:
        - price

    # Invoice Schemas
    Invoice:
      type: object
      properties:
        id:
          type: integer
          description: Invoice ID
          example: 33333
        order_id:
          type: integer
          description: Order ID the invoice belongs to
        amount:
          type: number
          format: decimal
          description: Invoice amount
        status:
          type: string
          enum: [pending, sent, paid]
          description: Invoice status
        sent_at:
          type: string
          format: date-time
          nullable: true
          description: Timestamp when invoice was sent
        created_at:
          type: string
          format: date-time
          description: Timestamp when invoice was created

    # Offer Schemas
    Offer:
      type: object
      properties:
        id:
          type: integer
          description: Offer ID
          example: 44444
        order_id:
          type: integer
          description: Order ID the offer belongs to
        carrier_pay:
          type: number
          format: decimal
          description: Offered carrier pay amount
        status:
          type: string
          enum: [pending, accepted, declined, expired]
          description: Offer status
        expires_at:
          type: string
          format: date-time
          nullable: true
          description: Timestamp when offer expires
        created_at:
          type: string
          format: date-time
          description: Timestamp when offer was created

    # Inspection Photo Schemas
    InspectionPhoto:
      type: object
      properties:
        id:
          type: integer
          description: Photo ID
          example: 55555
        vehicle_id:
          type: integer
          description: Vehicle ID the photo belongs to
        step:
          type: string
          enum: [pickup, delivery]
          description: Inspection step
        type:
          type: string
          description: Photo type
          example: "front_view"
        url:
          type: string
          format: uri
          description: URL to access the photo
        thumbnail_url:
          type: string
          format: uri
          nullable: true
          description: URL to access the thumbnail
        created_at:
          type: string
          format: date-time
          description: Timestamp when photo was uploaded

    # Damage Schemas
    Damage:
      type: object
      properties:
        id:
          type: integer
          description: Damage ID
          example: 66666
        vehicle_id:
          type: integer
          description: Vehicle ID the damage belongs to
        step:
          type: string
          enum: [pickup, delivery]
          description: Inspection step when damage was reported
        damage_type:
          type: string
          description: Type of damage
          example: "scratch"
        location:
          type: string
          description: Location of damage on vehicle
          example: "front_bumper"
        severity:
          type: string
          enum: [minor, moderate, severe]
          nullable: true
          description: Damage severity
        description:
          type: string
          nullable: true
          description: Damage description
        photo_url:
          type: string
          format: uri
          nullable: true
          description: URL to photo of damage
        created_at:
          type: string
          format: date-time
          description: Timestamp when damage was reported

    # Inspection Schemas
    Inspection:
      type: object
      properties:
        id:
          type: integer
          description: Inspection ID
          example: 77777
        vehicle_id:
          type: integer
          description: Vehicle ID the inspection belongs to
        step:
          type: string
          enum: [pickup, delivery]
          description: Inspection step
        completed:
          type: boolean
          description: Whether the inspection is completed
        signature:
          type: object
          nullable: true
          properties:
            url:
              type: string
              format: uri
              description: URL to signature image
            signed_by:
              type: string
              description: Name of person who signed
            signed_at:
              type: string
              format: date-time
              description: Timestamp when signed
        created_at:
          type: string
          format: date-time
          description: Timestamp when inspection was created
        updated_at:
          type: string
          format: date-time
          description: Timestamp when inspection was last updated

    # Signature Schemas
    Signature:
      type: object
      properties:
        id:
          type: integer
          description: Signature ID
          example: 88888
        order_id:
          type: integer
          description: Order ID the signature belongs to
        step:
          type: string
          enum: [pickup, delivery]
          description: Step when signature was collected
        url:
          type: string
          format: uri
          description: URL to signature image
        signed_by:
          type: string
          description: Name of person who signed
        signed_at:
          type: string
          format: date-time
          description: Timestamp when signed

    # Webhook Schemas
    WebhookSubscription:
      type: object
      description: A webhook event type and its subscription state
      properties:
        action:
          type: string
          description: Webhook event action name
          enum:
            - order.created
            - order.updated
            - order.assigned
            - order.picked_up
            - order.delivered
            - order.cancelled
            - order.status_changed
            - vehicle.inspection_created
            - vehicle.inspection_updated
            - damage.created
            - damage.deleted
        is_subscribed:
          type: boolean
          description: Whether the application is currently subscribed to this event
      required:
        - action
        - is_subscribed

    WebhookEvent:
      type: object
      description: Incoming webhook event payload
      properties:
        event_type:
          type: string
          description: Type of webhook event
          enum:
            - order.created
            - order.updated
            - order.assigned
            - order.picked_up
            - order.delivered
            - order.cancelled
            - order.status_changed
            - vehicle.inspection_created
            - vehicle.inspection_updated
            - damage.created
            - damage.deleted
        timestamp:
          type: string
          format: date-time
          description: Timestamp when event occurred
        data:
          type: object
          description: Event data (varies by event type)
      required:
        - event_type
        - timestamp
        - data

paths:
  # Authentication
  /oauth/token/:
    servers:
      - url: https://carrier.superdispatch.com
        description: Production Environment
      - url: https://staging.carrier.superdispatch.org
        description: Staging Environment
    post:
      tags:
        - Authentication
      summary: Get Access Token
      description: Obtain an OAuth 2.0 access token using client credentials
      operationId: getAccessToken
      security: []
      requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                grant_type:
                  type: string
                  enum: [client_credentials]
                  description: OAuth grant type
                client_id:
                  type: string
                  description: Client ID provided by Super Dispatch
                client_secret:
                  type: string
                  description: Client Secret provided by Super Dispatch
              required:
                - grant_type
                - client_id
                - client_secret
      responses:
        "200":
          description: Access token obtained successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  access_token:
                    type: string
                    description: Access token for API authentication
                  token_type:
                    type: string
                    enum: [Bearer]
                    description: Token type
                  expires_in:
                    type: integer
                    description: Number of seconds before the token expires
                  scope:
                    type: string
                    description: Space-separated list of scopes
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "401":
          description: Unauthorized - invalid credentials
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  # Carrier Endpoints
  /carriers/:
    get:
      tags:
        - Carriers
      summary: List Carriers
      description: Get a paginated list of all carriers associated with the application
      operationId: listCarriers
      parameters:
        - $ref: "#/components/parameters/per_page"
        - $ref: "#/components/parameters/page"
      responses:
        "200":
          description: List of carriers retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/Carrier"
                  pagination:
                    $ref: "#/components/schemas/Pagination"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /carriers/{id}/:
    get:
      tags:
        - Carriers
      summary: Retrieve Carrier
      description: Get details of a specific carrier
      operationId: getCarrier
      parameters:
        - $ref: "#/components/parameters/carrier_id"
      responses:
        "200":
          description: Carrier details retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Carrier"
        "404":
          description: Carrier not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  # Driver Endpoints
  /carriers/{id}/drivers/:
    get:
      tags:
        - Drivers
      summary: List Drivers
      description: Get a paginated list of all drivers for a carrier
      operationId: listDrivers
      parameters:
        - $ref: "#/components/parameters/carrier_id"
        - $ref: "#/components/parameters/per_page"
        - $ref: "#/components/parameters/page"
      responses:
        "200":
          description: List of drivers retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/Driver"
                  pagination:
                    $ref: "#/components/schemas/Pagination"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    post:
      tags:
        - Drivers
      summary: Invite Driver
      description: Invite a new driver to the carrier account
      operationId: inviteDriver
      parameters:
        - $ref: "#/components/parameters/carrier_id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/DriverBase"
      responses:
        "201":
          description: Driver invited successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Driver"
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /drivers/{id}/:
    get:
      tags:
        - Drivers
      summary: Get a Driver
      description: Get details of a specific driver
      operationId: getDriver
      parameters:
        - $ref: "#/components/parameters/driver_id"
      responses:
        "200":
          description: Driver details retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Driver"
        "404":
          description: Driver not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    put:
      tags:
        - Drivers
      summary: Update a Driver
      description: Update an existing driver (full update)
      operationId: updateDriver
      parameters:
        - $ref: "#/components/parameters/driver_id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/DriverBase"
      responses:
        "200":
          description: Driver updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Driver"
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: Driver not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    patch:
      tags:
        - Drivers
      summary: Update a Driver (Partial)
      description: Partially update an existing driver
      operationId: patchDriver
      parameters:
        - $ref: "#/components/parameters/driver_id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                email:
                  type: string
                  format: email
                phone:
                  type: string
                truck_capacity:
                  type: integer
      responses:
        "200":
          description: Driver updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Driver"
        "404":
          description: Driver not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  # Order Endpoints
  /orders/:
    post:
      tags:
        - Orders
      summary: Create an Order
      description: Create a new order
      operationId: createOrder
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/OrderBase"
      responses:
        "201":
          description: Order created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Order"
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    get:
      tags:
        - Orders
      summary: List Orders
      description: Get a paginated list of all orders
      operationId: listOrders
      parameters:
        - $ref: "#/components/parameters/per_page"
        - $ref: "#/components/parameters/page"
        - name: status
          in: query
          description: Filter by order status
          schema:
            type: string
            enum:
              [
                unassigned,
                assigned,
                picked_up,
                in_transit,
                delivered,
                archived,
                billed,
                paid,
              ]
      responses:
        "200":
          description: List of orders retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/Order"
                  pagination:
                    $ref: "#/components/schemas/Pagination"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /orders/{id}/:
    get:
      tags:
        - Orders
      summary: Get an Order
      description: Get details of a specific order
      operationId: getOrder
      parameters:
        - $ref: "#/components/parameters/order_id"
      responses:
        "200":
          description: Order details retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Order"
        "404":
          description: Order not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    put:
      tags:
        - Orders
      summary: Update an Order
      description: Update an existing order (full update)
      operationId: updateOrder
      parameters:
        - $ref: "#/components/parameters/order_id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/OrderBase"
      responses:
        "200":
          description: Order updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Order"
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: Order not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    patch:
      tags:
        - Orders
      summary: Update an Order (Partial)
      description: Partially update an existing order
      operationId: patchOrder
      parameters:
        - $ref: "#/components/parameters/order_id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
      responses:
        "200":
          description: Order updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Order"
        "404":
          description: Order not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    delete:
      tags:
        - Orders
      summary: Delete an Order
      description: Delete an existing order
      operationId: deleteOrder
      parameters:
        - $ref: "#/components/parameters/order_id"
      responses:
        "204":
          description: Order deleted successfully
        "404":
          description: Order not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /orders/{id}/mark-as-picked-up/:
    post:
      tags:
        - Orders
      summary: Mark Order as Picked Up
      description: Mark an order as picked up
      operationId: markOrderPickedUp
      parameters:
        - $ref: "#/components/parameters/order_id"
      responses:
        "200":
          description: Order marked as picked up successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Order"
        "404":
          description: Order not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /orders/{id}/mark-as-delivered/:
    post:
      tags:
        - Orders
      summary: Mark Order as Delivered
      description: Mark an order as delivered
      operationId: markOrderDelivered
      parameters:
        - $ref: "#/components/parameters/order_id"
      responses:
        "200":
          description: Order marked as delivered successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Order"
        "404":
          description: Order not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /orders/{id}/assign-driver/:
    post:
      tags:
        - Orders
      summary: Assign Driver to Order
      description: Assign a driver to an order
      operationId: assignDriver
      parameters:
        - $ref: "#/components/parameters/order_id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                driver_id:
                  type: integer
                  description: Driver ID to assign
              required:
                - driver_id
      responses:
        "200":
          description: Driver assigned successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Order"
        "404":
          description: Order or driver not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /orders/{id}/unassign-driver/:
    post:
      tags:
        - Orders
      summary: Unassign Driver from Order
      description: Unassign the driver from an order
      operationId: unassignDriver
      parameters:
        - $ref: "#/components/parameters/order_id"
      responses:
        "200":
          description: Driver unassigned successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Order"
        "404":
          description: Order not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /orders/{id}/cancel/:
    post:
      tags:
        - Orders
      summary: Cancel Order
      description: Cancel an order
      operationId: cancelOrder
      parameters:
        - $ref: "#/components/parameters/order_id"
      responses:
        "200":
          description: Order cancelled successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Order"
        "404":
          description: Order not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /orders/{id}/split/:
    post:
      tags:
        - Orders
      summary: Split Order
      description: Split an order into multiple orders
      operationId: splitOrder
      parameters:
        - $ref: "#/components/parameters/order_id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                vehicle_ids:
                  type: array
                  items:
                    type: integer
                  description: List of vehicle IDs to split into a new order
              required:
                - vehicle_ids
      responses:
        "200":
          description: Order split successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/Order"
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: Order not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /orders/{id}/bol/:
    get:
      tags:
        - Orders
      summary: Get Order BOL
      description: Get the Bill of Lading for an order
      operationId: getOrderBOL
      parameters:
        - $ref: "#/components/parameters/order_id"
      responses:
        "200":
          description: BOL retrieved successfully
          content:
            application/pdf:
              schema:
                type: string
                format: binary
        "404":
          description: Order not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /orders/{id}/driver_location/:
    get:
      tags:
        - Orders
      summary: Get Driver Location
      description: Get the current GPS location of the driver assigned to an order
      operationId: getDriverLocation
      parameters:
        - $ref: "#/components/parameters/order_id"
      responses:
        "200":
          description: Driver location retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/DriverLocation"
        "404":
          description: Order not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  # Order Attachments
  /orders/{id}/attachments/:
    post:
      tags:
        - Order Attachments
      summary: Add an Attachment
      description: Add an attachment to an order
      operationId: addAttachment
      parameters:
        - $ref: "#/components/parameters/order_id"
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
                  description: File to upload
              required:
                - file
      responses:
        "201":
          description: Attachment added successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Attachment"
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    get:
      tags:
        - Order Attachments
      summary: List Attachments
      description: Get all attachments for an order
      operationId: listAttachments
      parameters:
        - $ref: "#/components/parameters/order_id"
      responses:
        "200":
          description: List of attachments retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/Attachment"
        "404":
          description: Order not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /order_attachments/{id}/:
    get:
      tags:
        - Order Attachments
      summary: Get an Attachment
      description: Get details of a specific attachment
      operationId: getAttachment
      parameters:
        - $ref: "#/components/parameters/attachment_id"
      responses:
        "200":
          description: Attachment details retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Attachment"
        "404":
          description: Attachment not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  # Vehicle Endpoints
  /orders/{id}/vehicles/:
    post:
      tags:
        - Vehicles
      summary: Create a Vehicle
      description: Add a new vehicle to an order
      operationId: createVehicle
      parameters:
        - $ref: "#/components/parameters/order_id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/VehicleInfo"
      responses:
        "201":
          description: Vehicle created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Vehicle"
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    get:
      tags:
        - Vehicles
      summary: List Vehicles
      description: Get all vehicles for an order
      operationId: listVehicles
      parameters:
        - $ref: "#/components/parameters/order_id"
      responses:
        "200":
          description: List of vehicles retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/Vehicle"
        "404":
          description: Order not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /vehicles/{id}/:
    get:
      tags:
        - Vehicles
      summary: Get a Vehicle
      description: Get details of a specific vehicle
      operationId: getVehicle
      parameters:
        - $ref: "#/components/parameters/vehicle_id"
      responses:
        "200":
          description: Vehicle details retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Vehicle"
        "404":
          description: Vehicle not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    put:
      tags:
        - Vehicles
      summary: Update a Vehicle
      description: Update an existing vehicle (full update)
      operationId: updateVehicle
      parameters:
        - $ref: "#/components/parameters/vehicle_id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/VehicleInfo"
      responses:
        "200":
          description: Vehicle updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Vehicle"
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: Vehicle not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    patch:
      tags:
        - Vehicles
      summary: Update a Vehicle (Partial)
      description: Partially update an existing vehicle
      operationId: patchVehicle
      parameters:
        - $ref: "#/components/parameters/vehicle_id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
      responses:
        "200":
          description: Vehicle updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Vehicle"
        "404":
          description: Vehicle not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    delete:
      tags:
        - Vehicles
      summary: Delete a Vehicle
      description: Delete a vehicle from an order
      operationId: deleteVehicle
      parameters:
        - $ref: "#/components/parameters/vehicle_id"
      responses:
        "204":
          description: Vehicle deleted successfully
        "404":
          description: Vehicle not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /vehicles/{id}/bol/:
    get:
      tags:
        - Vehicles
      summary: Get Vehicle BOL
      description: Get the Bill of Lading for a specific vehicle
      operationId: getVehicleBOL
      parameters:
        - $ref: "#/components/parameters/vehicle_id"
      responses:
        "200":
          description: BOL retrieved successfully
          content:
            application/pdf:
              schema:
                type: string
                format: binary
        "404":
          description: Vehicle not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /vehicles/{id}/aiag-damages/:
    get:
      tags:
        - Vehicles
      summary: Retrieve Vehicle AIAG Damages
      description: Get AIAG inspection damages for a vehicle (only available on orders with AIAG inspection type)
      operationId: getVehicleAIAGDamages
      parameters:
        - $ref: "#/components/parameters/vehicle_id"
      responses:
        "200":
          description: AIAG damages retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    type: array
                    items:
                      type: object
                      description: AIAG inspection record with damages
        "404":
          description: Vehicle not found or not on an AIAG inspection order
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  # Expense Endpoints
  /orders/{id}/expenses/:
    get:
      tags:
        - Expenses
      summary: List Expenses
      description: Get all expenses for an order
      operationId: listExpenses
      parameters:
        - $ref: "#/components/parameters/order_id"
      responses:
        "200":
          description: List of expenses retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/Expense"
        "404":
          description: Order not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    post:
      tags:
        - Expenses
      summary: Add an Expense
      description: Add a new expense to an order
      operationId: addExpense
      parameters:
        - $ref: "#/components/parameters/order_id"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                price:
                  type: number
                  format: decimal
                  description: Expense amount (negative = deduction)
                type:
                  type: string
                  nullable: true
                  description: Expense type (e.g. fuel, other)
                name_for_type_other:
                  type: string
                  nullable: true
                  description: Custom name when type is "other"
                receipt_date:
                  type: string
                  format: date-time
                  nullable: true
                show_on_invoice:
                  type: boolean
                  nullable: true
                deduct_from_driver_pay:
                  type: boolean
                  nullable: true
              required:
                - price
      responses:
        "201":
          description: Expense added successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Expense"
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /expenses/{id}/:
    get:
      tags:
        - Expenses
      summary: Get an Expense
      description: Get details of a specific expense
      operationId: getExpense
      parameters:
        - $ref: "#/components/parameters/expense_id"
      responses:
        "200":
          description: Expense details retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Expense"
        "404":
          description: Expense not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    delete:
      tags:
        - Expenses
      summary: Delete an Expense
      description: Delete an expense from an order
      operationId: deleteExpense
      parameters:
        - $ref: "#/components/parameters/expense_id"
      responses:
        "204":
          description: Expense deleted successfully
        "404":
          description: Expense not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  # Invoice Endpoints
  /invoices/send/:
    post:
      tags:
        - Invoices
      summary: Send Invoice
      description: Generate and send an invoice. Takes order IDs in the request body.
      operationId: sendInvoice
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                order_ids:
                  type: array
                  items:
                    type: integer
                  description: List of order IDs to invoice
                email:
                  type: string
                  format: email
                  description: Recipient email address
                invoice_id:
                  type: string
                  description: Invoice number/identifier
                invoice_date:
                  type: string
                  format: date
                  description: Invoice date
                customer_name:
                  type: string
                  nullable: true
                  description: Customer name on the invoice
                factor_this_invoice:
                  type: boolean
                  default: false
                  description: Whether to factor this invoice
              required:
                - order_ids
                - email
                - invoice_id
                - invoice_date
      responses:
        "204":
          description: Invoice sent successfully
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: Order not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  # Offer Endpoints
  /offers/:
    get:
      tags:
        - Offers
      summary: List Offers
      description: Get a paginated list of all offers for the application's carriers
      operationId: listOffers
      parameters:
        - $ref: "#/components/parameters/per_page"
        - $ref: "#/components/parameters/page"
        - name: status
          in: query
          description: Filter by offer status
          schema:
            type: string
            enum: [pending, accepted, declined, expired]
      responses:
        "200":
          description: List of offers retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/Offer"
                  pagination:
                    $ref: "#/components/schemas/Pagination"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /offers/{id}/:
    get:
      tags:
        - Offers
      summary: Get an Offer
      description: Get details of a specific offer
      operationId: getOffer
      parameters:
        - $ref: "#/components/parameters/offer_id"
      responses:
        "200":
          description: Offer details retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Offer"
        "404":
          description: Offer not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /offers/{id}/accept/:
    post:
      tags:
        - Offers
      summary: Accept an Offer
      description: Accept a pending offer
      operationId: acceptOffer
      parameters:
        - $ref: "#/components/parameters/offer_id"
      responses:
        "200":
          description: Offer accepted successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Offer"
        "404":
          description: Offer not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /offers/{id}/decline/:
    post:
      tags:
        - Offers
      summary: Decline an Offer
      description: Decline a pending offer
      operationId: declineOffer
      parameters:
        - $ref: "#/components/parameters/offer_id"
      responses:
        "200":
          description: Offer declined successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Offer"
        "404":
          description: Offer not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  # Inspection Photo Endpoints
  /vehicles/{id}/photos/:
    post:
      tags:
        - Inspection Photos
      summary: Send Vehicle Photo
      description: Upload a vehicle inspection photo
      operationId: sendVehiclePhoto
      parameters:
        - $ref: "#/components/parameters/vehicle_id"
        - name: step
          in: query
          required: true
          description: Inspection step (pickup or delivery)
          schema:
            type: string
            enum: [pickup, delivery]
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                photo:
                  type: string
                  format: binary
                  description: Photo file to upload
                type:
                  type: string
                  description: Photo type
              required:
                - photo
      responses:
        "201":
          description: Photo uploaded successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/InspectionPhoto"
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    get:
      tags:
        - Inspection Photos
      summary: Receive Vehicle Photos
      description: Get all inspection photos for a vehicle
      operationId: receiveVehiclePhotos
      parameters:
        - $ref: "#/components/parameters/vehicle_id"
        - name: step
          in: query
          description: Filter by inspection step
          schema:
            type: string
            enum: [pickup, delivery]
      responses:
        "200":
          description: List of photos retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/InspectionPhoto"
        "404":
          description: Vehicle not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /photos/{id}/:
    get:
      tags:
        - Inspection Photos
      summary: Receive Vehicle Photo by ID
      description: Get a specific inspection photo by ID
      operationId: receiveVehiclePhotoById
      parameters:
        - $ref: "#/components/parameters/photo_id"
      responses:
        "200":
          description: Photo details retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/InspectionPhoto"
        "404":
          description: Photo not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    delete:
      tags:
        - Inspection Photos
      summary: Delete Vehicle Photo
      description: Delete an inspection photo
      operationId: deleteVehiclePhoto
      parameters:
        - $ref: "#/components/parameters/photo_id"
      responses:
        "204":
          description: Photo deleted successfully
        "404":
          description: Photo not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  # Damage Endpoints
  /photos/{photo_id}/damages/:
    post:
      tags:
        - Damages
      summary: Send Vehicle Damages
      description: Report damage on a vehicle, keyed off the inspection photo
      operationId: sendVehicleDamages
      parameters:
        - name: photo_id
          in: path
          required: true
          description: Inspection photo ID
          schema:
            type: integer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                code:
                  type: string
                  description: Damage code
                notes:
                  type: string
                  nullable: true
                  description: Damage notes
              required:
                - code
      responses:
        "201":
          description: Damage reported successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Damage"
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    get:
      tags:
        - Damages
      summary: Receive Vehicle Damages
      description: Get all damages for an inspection photo
      operationId: receiveVehicleDamages
      parameters:
        - name: photo_id
          in: path
          required: true
          description: Inspection photo ID
          schema:
            type: integer
      responses:
        "200":
          description: List of damages retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/Damage"
                  pagination:
                    $ref: "#/components/schemas/Pagination"
        "404":
          description: Photo not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    delete:
      tags:
        - Damages
      summary: Delete All Damages for a Photo
      description: Delete all damage reports associated with an inspection photo
      operationId: deleteVehicleDamagesByPhoto
      parameters:
        - name: photo_id
          in: path
          required: true
          description: Inspection photo ID
          schema:
            type: integer
      responses:
        "204":
          description: Damages deleted successfully
        "404":
          description: Photo not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /damages/{id}/:
    get:
      tags:
        - Damages
      summary: Receive Vehicle Damage by ID
      description: Get a specific damage by ID
      operationId: receiveVehicleDamageById
      parameters:
        - $ref: "#/components/parameters/damage_id"
      responses:
        "200":
          description: Damage details retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Damage"
        "404":
          description: Damage not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    delete:
      tags:
        - Damages
      summary: Delete Vehicle Damage
      description: Delete a damage report
      operationId: deleteVehicleDamage
      parameters:
        - $ref: "#/components/parameters/damage_id"
      responses:
        "204":
          description: Damage deleted successfully
        "404":
          description: Damage not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  # Inspection Endpoints
  /vehicles/{vehicle_id}/inspections/{step}/:
    post:
      tags:
        - Inspections
      summary: Send Vehicle Inspection
      description: Create a vehicle inspection for a specific step
      operationId: sendVehicleInspection
      parameters:
        - name: vehicle_id
          in: path
          required: true
          description: Vehicle ID
          schema:
            type: integer
        - name: step
          in: path
          required: true
          description: Inspection step
          schema:
            type: string
            enum: [pickup, delivery]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                completed:
                  type: boolean
      responses:
        "201":
          description: Inspection created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Inspection"
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    get:
      tags:
        - Inspections
      summary: Receive Vehicle Inspection by Step
      description: Get a vehicle inspection for a specific step
      operationId: receiveVehicleInspectionByStep
      parameters:
        - name: vehicle_id
          in: path
          required: true
          description: Vehicle ID
          schema:
            type: integer
        - name: step
          in: path
          required: true
          description: Inspection step
          schema:
            type: string
            enum: [pickup, delivery]
      responses:
        "200":
          description: Inspection details retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Inspection"
        "404":
          description: Inspection not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    patch:
      tags:
        - Inspections
      summary: Update Vehicle Inspection by Step
      description: Partially update a vehicle inspection for a specific step
      operationId: updateVehicleInspectionByStep
      parameters:
        - name: vehicle_id
          in: path
          required: true
          description: Vehicle ID
          schema:
            type: integer
        - name: step
          in: path
          required: true
          description: Inspection step
          schema:
            type: string
            enum: [pickup, delivery]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                completed:
                  type: boolean
      responses:
        "200":
          description: Inspection updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Inspection"
        "404":
          description: Inspection not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  # Signature Endpoints
  /orders/{order_id}/signatures/{step}/:
    post:
      tags:
        - Signatures
      summary: Send Signature
      description: Upload a signature for an order
      operationId: sendSignature
      parameters:
        - name: order_id
          in: path
          required: true
          description: Order ID
          schema:
            type: integer
        - name: step
          in: path
          required: true
          description: Signature step
          schema:
            type: string
            enum: [pickup, delivery]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                url:
                  type: string
                  format: uri
                  description: URL to the signature image
                owner:
                  type: string
                  description: Role of the signer (e.g. driver, customer)
                signer_name:
                  type: string
                  description: Name of the person who signed
                latitude:
                  type: number
                  format: double
                  nullable: true
                  description: Latitude where signature was captured
                longitude:
                  type: number
                  format: double
                  nullable: true
                  description: Longitude where signature was captured
                signed_at:
                  type: string
                  format: date-time
                  description: Timestamp when signature was captured
              required:
                - url
                - signer_name
      responses:
        "201":
          description: Signature uploaded successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/Signature"
        "400":
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    get:
      tags:
        - Signatures
      summary: Receive Signatures by Step
      description: Get signatures for a specific step
      operationId: receiveSignaturesByStep
      parameters:
        - name: order_id
          in: path
          required: true
          description: Order ID
          schema:
            type: integer
        - name: step
          in: path
          required: true
          description: Signature step
          schema:
            type: string
            enum: [pickup, delivery]
      responses:
        "200":
          description: Signatures retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/Signature"
        "404":
          description: Order not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  # Webhook Management Endpoints
  /webhooks/:
    get:
      tags:
        - Webhooks
      summary: List Webhook Events
      description: Get a list of all available webhook event types that can be subscribed to
      operationId: listWebhooks
      responses:
        "200":
          description: List of webhook events retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/WebhookSubscription"
                  pagination:
                    $ref: "#/components/schemas/Pagination"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /webhooks/{action}/:
    get:
      tags:
        - Webhooks
      summary: Retrieve Webhook Event
      description: Get details of a specific webhook event type by its action name (e.g. `order.created`)
      operationId: getWebhook
      parameters:
        - name: action
          in: path
          required: true
          description: Webhook event action name (e.g. order.created, order.updated)
          schema:
            type: string
            example: order.created
      responses:
        "200":
          description: Webhook event details retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    $ref: "#/components/schemas/WebhookSubscription"
        "404":
          description: Webhook event not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

  /webhooks/{action}/subscriptions/:
    post:
      tags:
        - Webhooks
      summary: Subscribe to Webhook Event
      description: Subscribe the application to a specific webhook event. Use the event action name in the path (e.g. `order.created`).
      operationId: subscribeWebhook
      parameters:
        - name: action
          in: path
          required: true
          description: Webhook event action name (e.g. order.created)
          schema:
            type: string
            example: order.created
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                callback_url:
                  type: string
                  format: uri
                  description: URL that will receive webhook POST requests
              required:
                - callback_url
      responses:
        "201":
          description: Subscription created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  meta:
                    $ref: "#/components/schemas/Meta"
                  data:
                    type: object
                    properties:
                      callback_url:
                        type: string
                        format: uri
        "400":
          description: Bad Request (e.g. subscription already exists)
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: Webhook event not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

    delete:
      tags:
        - Webhooks
      summary: Unsubscribe from Webhook Event
      description: Remove the application's subscription to a specific webhook event
      operationId: unsubscribeWebhook
      parameters:
        - name: action
          in: path
          required: true
          description: Webhook event action name (e.g. order.created)
          schema:
            type: string
            example: order.created
      responses:
        "204":
          description: Subscription deleted successfully
        "404":
          description: Subscription not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"

webhooks:
  order.created:
    post:
      tags:
        - Webhooks
      summary: Order Created
      description: Triggered when a new order is created
      requestBody:
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/WebhookEvent"
                - type: object
                  properties:
                    event_type:
                      enum: [order.created]
                    data:
                      $ref: "#/components/schemas/Order"
      responses:
        "200":
          description: Webhook received successfully

  order.updated:
    post:
      tags:
        - Webhooks
      summary: Order Updated
      description: Triggered when an order is updated
      requestBody:
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/WebhookEvent"
                - type: object
                  properties:
                    event_type:
                      enum: [order.updated]
                    data:
                      $ref: "#/components/schemas/Order"
      responses:
        "200":
          description: Webhook received successfully

  order.assigned:
    post:
      tags:
        - Webhooks
      summary: Order Assigned
      description: Triggered when an order is assigned to a driver
      requestBody:
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/WebhookEvent"
                - type: object
                  properties:
                    event_type:
                      enum: [order.assigned]
                    data:
                      $ref: "#/components/schemas/Order"
      responses:
        "200":
          description: Webhook received successfully

  order.picked_up:
    post:
      tags:
        - Webhooks
      summary: Order Picked Up
      description: Triggered when an order is marked as picked up
      requestBody:
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/WebhookEvent"
                - type: object
                  properties:
                    event_type:
                      enum: [order.picked_up]
                    data:
                      $ref: "#/components/schemas/Order"
      responses:
        "200":
          description: Webhook received successfully

  order.delivered:
    post:
      tags:
        - Webhooks
      summary: Order Delivered
      description: Triggered when an order is marked as delivered
      requestBody:
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/WebhookEvent"
                - type: object
                  properties:
                    event_type:
                      enum: [order.delivered]
                    data:
                      $ref: "#/components/schemas/Order"
      responses:
        "200":
          description: Webhook received successfully

  order.cancelled:
    post:
      tags:
        - Webhooks
      summary: Order Cancelled
      description: Triggered when an order is cancelled
      requestBody:
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/WebhookEvent"
                - type: object
                  properties:
                    event_type:
                      enum: [order.cancelled]
                    data:
                      $ref: "#/components/schemas/Order"
      responses:
        "200":
          description: Webhook received successfully

  vehicle.inspection_created:
    post:
      tags:
        - Webhooks
      summary: Vehicle Inspection Created
      description: Triggered when a vehicle inspection is created
      requestBody:
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/WebhookEvent"
                - type: object
                  properties:
                    event_type:
                      enum: [vehicle.inspection_created]
                    data:
                      $ref: "#/components/schemas/Inspection"
      responses:
        "200":
          description: Webhook received successfully

  vehicle.inspection_updated:
    post:
      tags:
        - Webhooks
      summary: Vehicle Inspection Updated
      description: Triggered when a vehicle inspection is updated
      requestBody:
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/WebhookEvent"
                - type: object
                  properties:
                    event_type:
                      enum: [vehicle.inspection_updated]
                    data:
                      $ref: "#/components/schemas/Inspection"
      responses:
        "200":
          description: Webhook received successfully

  damage.created:
    post:
      tags:
        - Webhooks
      summary: Damage Created
      description: Triggered when a damage report is created
      requestBody:
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/WebhookEvent"
                - type: object
                  properties:
                    event_type:
                      enum: [damage.created]
                    data:
                      $ref: "#/components/schemas/Damage"
      responses:
        "200":
          description: Webhook received successfully

  damage.deleted:
    post:
      tags:
        - Webhooks
      summary: Damage Deleted
      description: Triggered when a damage report is deleted
      requestBody:
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/WebhookEvent"
                - type: object
                  properties:
                    event_type:
                      enum: [damage.deleted]
                    data:
                      type: object
                      properties:
                        id:
                          type: integer
                          description: Deleted damage ID
      responses:
        "200":
          description: Webhook received successfully
