openapi: 3.0.3
info:
  title: Extraction API On-Prem
  version: 1.0.0

paths:
  /api/emails/scrape_e_receipt:
    post:
      summary: Scrape one or more e-receipts from email payloads
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ScrapeEReceiptRequest'
      responses:
        '200':
          description: Successful scrape
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClientFormatOutputDataResult'

components:
  schemas:

    # ──────────────────────────────────────────────────────────────────────────
    # Request schema
    # ──────────────────────────────────────────────────────────────────────────

    ScrapeEReceiptRequest:
      type: object
      required:
        - ereceipt
      properties:
        ereceipt:
          type: array
          description: One or more e-receipts to process
          minItems: 1
          items:
            $ref: '#/components/schemas/EmailMessage'
        is_forwarded:
          type: boolean
          nullable: true
          description: Indicates if the email was forwarded

    EmailMessage:
      type: object
      properties:
        index:
          type: integer
          nullable: true
          description: Position in batch
        eml:
          type: string
          nullable: false
          description: Raw EML payload

    # ──────────────────────────────────────────────────────────────────────────
    # Response schemas
    # ──────────────────────────────────────────────────────────────────────────

    FormattedSubProduct:
      type: object
      description: A sub-product line item in the client format
      properties:
        index:
          type: integer
          description: Position of the sub-product
        e_receipt_short_description:
          type: string
          nullable: true
        quantity:
          type: integer
          nullable: true
        total_price:
          type: number
          nullable: true

    ClientFormattedProduct:
      type: object
      description: A product line item in the client format
      properties:
        index:
          type: integer
          description: Position of the product
        e_receipt_product_number:
          type: string
          nullable: true
        e_receipt_short_description:
          type: string
          nullable: true
        quantity:
          type: integer
          nullable: true
        total_price:
          type: number
          nullable: true
        unit_price:
          type: number
          nullable: true
        full_price:
          type: number
          nullable: true
        scraped_image_url:
          type: string
          nullable: true
        scraped_product_url:
          type: string
          nullable: true
        sub_products:
          type: array
          items:
            $ref: '#/components/schemas/FormattedSubProduct'

    ClientFormatOutputDataResult:
      type: object
      description: The client-facing formatted receipt
      properties:
        index:
          type: integer
          nullable: true
        merchant_name:
          type: string
          nullable: true
        sub_merchant:
          type: string
          nullable: true
        order_number:
          type: string
          nullable: true
        shipping_costs:
          type: number
          nullable: true
        order_status:
          type: string
          nullable: true
        purchase_type:
          type: string
          nullable: true
        currency_code:
          type: string
          nullable: true
        payment_method:
          type: string
          nullable: true
        last_4_cc:
          type: string
          nullable: true
        card_type:
          type: string
          nullable: true
        banner_id:
          type: integer
          nullable: true
        delivery_date:
          type: string
          nullable: true
        product_count:
          type: integer
          nullable: true
        total:
          type: number
          nullable: true
        subtotal:
          type: number
          nullable: true
        taxes:
          type: number
          nullable: true
        fees:
          type: number
          nullable: true
        tip:
          type: number
          nullable: true
        blink_receipt_id:
          type: string
          nullable: true
        client_merchant_name:
          type: string
          nullable: true
        order_date:
          type: string
          nullable: true
        is_ereceipt:
          type: boolean
        fulfilled_by:
          type: string
          nullable: true
        pos_system:
          type: string
          nullable: true
        scraped_product_count:
          type: number
          nullable: true
        is_e_receipt:
          type: boolean
          nullable: true
        store_street:
          type: string
          nullable: true
        store_zip:
          type: string
          nullable: true
        store_city:
          type: string
          nullable: true
        store_state:
          type: string
          nullable: true
        store_phone:
          type: string
          nullable: true
        country_code:
          type: string
          nullable: true
        products:
          type: array
          items:
            $ref: '#/components/schemas/ClientFormattedProduct'
          nullable: true
  securitySchemes:
    UIDHeader:
      type: apiKey
      in: header
      name: uid
    APITokenHeader:
      type: apiKey
      in: header
      name: api-token
security:
  - UIDHeader: []
    APITokenHeader: []