openapi: 3.0.0
info:
  title: Scale API
  version: 1.0.0
  description: >
    The Scale API manages scale tickets with inbound and outbound flow data for
    the Hauler Hero platform.


    ## Integration Prerequisites


    **Important:** If you want to integrate your scale tickets into the Hauler
    Hero platform, you must call this API endpoint with the required data
    specified in this specification.


    Partners need to:

    1. **Obtain API credentials** (HERO-API-KEY) from Hauler Hero. *Important:
    Each Hauler Hero account has a unique API key.*

    2. **Call the POST /hero-api/v1/tickets endpoint** whenever a scale ticket
    is created or updated in your system

    3. **Send the required data** including site, materials, and flow
    information as specified in the request schema

    4. **Receive confirmation** that the ticket was successfully integrated into
    Hauler Hero


    ## What Data to Send


    When calling this API, you must include:

    - **Site identification** - UUID for the site

    - **Material quantities** - List of materials with IDs, names, quantities,
    pricing, and units

    - **Inbound/Outbound flow data** - Ticket numbers, effective dates


    ## Authentication


    All endpoints require API key authentication using the `HERO-API-KEY`
    header.
servers:
  - url: https://api.haulerhero.com
    description: Hauler Hero production server
security:
  - apiKey: []
tags:
  - name: Scale Tickets
    description: Scale ticket and weighing operations
paths:
  /hero-api/v1/tickets:
    post:
      tags:
        - Scale Tickets
      summary: Create a scale ticket
      description: >-
        Creates a new scale ticket with weight measurements, materials, and
        vehicle information
      operationId: addScaleTicket
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateScaleTicketRequest'
            examples:
              basicTicket:
                summary: Basic scale ticket with inbound and outbound flows
                value:
                  siteId: 64318450-1ce2-499d-8a70-f313aabe1831
                  materials:
                    - id: a51b814b-1b23-4f28-8c2a-b90030340eea
                      name: Paper
                      quantity: 100
                      unitPriceCents: 15.5
                      unitOfMeasure: Ton
                  inboundFlow:
                    ticketNumber: INB-20240701-001
                    updatedAt: '2024-07-01T12:00:00Z'
                  outboundFlow:
                    ticketNumber: OUT-20250701-001
                    updatedAt: '2025-07-01T12:00:00Z'
      responses:
        '200':
          description: Scale ticket created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateScaleTicketResponse'
              example:
                success: true
                disposalTicketId: 123e4567-e89b-12d3-a456-426614174000
        '400':
          description: Bad request - Invalid payload or missing required fields
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: INVALID_PAYLOAD
                  message: 'Missing required field: siteId'
        '401':
          description: Unauthorized - Invalid or missing authentication
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: UNAUTHORIZED
                  message: Invalid API key
        '422':
          description: Validation exception - Business rule violation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: VALIDATION_ERROR
                  message: Material ID does not exist in the system
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: INTERNAL_ERROR
                  message: >-
                    An unexpected error occurred while processing the scale
                    ticket
components:
  schemas:
    CreateScaleTicketRequest:
      type: object
      required:
        - siteId
        - materials
      properties:
        siteId:
          type: string
          format: uuid
          description: Unique identifier for the disposal site
          example: 64318450-1ce2-499d-8a70-f313aabe1831
        materials:
          type: array
          items:
            $ref: '#/components/schemas/MaterialItem'
          minItems: 1
          description: List of materials with quantities
        inboundFlow:
          $ref: '#/components/schemas/FlowData'
        outboundFlow:
          $ref: '#/components/schemas/FlowData'
    CreateScaleTicketResponse:
      type: object
      required:
        - success
        - disposalTicketId
      properties:
        success:
          type: boolean
          description: Whether the request was successful
          example: true
        disposalTicketId:
          type: string
          format: uuid
          description: Unique identifier for the created disposal ticket
          example: 123e4567-e89b-12d3-a456-426614174000
    MaterialItem:
      type: object
      required:
        - id
        - name
        - quantity
        - unitOfMeasure
      properties:
        id:
          type: string
          format: uuid
          description: Unique identifier for the material
          example: a51b814b-1b23-4f28-8c2a-b90030340eea
        name:
          type: string
          description: Material name
          example: Paper
        quantity:
          type: number
          description: Quantity of the material
          example: 100
        unitPriceCents:
          type: number
          format: double
          description: Unit price in cents (e.g., 15.50 for $0.155)
          example: 15.5
        unitOfMeasure:
          type: string
          description: Unit of measurement for the material
          example: Ton
          enum:
            - Ton
            - Gallon
            - Pound
            - Kilogram
            - Cubic Yard
            - Cubic Meter
            - Item
    FlowData:
      type: object
      required:
        - ticketNumber
        - updatedAt
      properties:
        ticketNumber:
          type: string
          description: Unique ticket number for this flow (inbound or outbound)
          example: INB-20240701-001
        updatedAt:
          type: string
          format: date-time
          description: Timestamp when this flow was last updated
          example: '2024-07-01T12:00:00Z'
    ErrorResponse:
      type: object
      required:
        - success
        - error
      properties:
        success:
          type: boolean
          description: Always false for errors
          example: false
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              description: Machine-readable error code
              example: INVALID_PAYLOAD
              enum:
                - INVALID_PAYLOAD
                - UNAUTHORIZED
                - INTERNAL_ERROR
                - VALIDATION_ERROR
            message:
              type: string
              description: Human-readable error message
              example: 'Missing required field: siteId'
            details:
              type: object
              description: Additional error details (optional)
              additionalProperties: true
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: HERO-API-KEY
      description: |
        API key for authenticating requests.

        To obtain an API key:
        - Contact your account manager
        - Email: api-support@haulerhero.com

        Include in request header: `HERO-API-KEY: your_api_key_here`
