openapi: 3.0.0
info:
  title: OCR Invoice Job Page API
  description: API for managing individual pages within OCR invoice jobs
  version: 1.0.0
  contact:
    name: Repzo
    url: https://repzo.com

servers:
  - url: https://sv.api.repzo.me
    description: Production server
  - url: https://staging.sv.api.repzo.me
    description: Staging server

tags:
  - name: OCR Invoice Job Page
    description: Operations related to individual pages within OCR invoice jobs

paths:
  /ocr-invoice-job-page:
    get:
      tags:
        - OCR Invoice Job Page
      summary: Get all OCR invoice job pages
      description: Retrieve a list of all OCR invoice job pages with optional filtering and pagination
      parameters:
        - name: limit
          in: query
          description: Maximum number of records to return
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 50
        - name: offset
          in: query
          description: Number of records to skip for pagination
          required: false
          schema:
            type: integer
            minimum: 0
            default: 0
        - name: sort
          in: query
          description: Field to sort by
          required: false
          schema:
            type: string
        - name: order
          in: query
          description: Sort order (asc or desc)
          required: false
          schema:
            type: string
            enum: [asc, desc]
            default: desc
        - name: filter
          in: query
          description: Filter conditions in JSON format
          required: false
          schema:
            type: string
        - name: search
          in: query
          description: Search term for text fields
          required: false
          schema:
            type: string
      responses:
        "200":
          description: List of OCR invoice job pages retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/OcrInvoiceJobPage"
                  total:
                    type: integer
                    description: Total number of records
        "400":
          description: Bad request
        "401":
          description: Unauthorized
        "500":
          description: Internal server error
    post:
      tags:
        - OCR Invoice Job Page
      summary: Create a new OCR invoice job page
      description: Create a new OCR invoice job page with the provided data
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/OcrInvoiceJobPageInput"
      responses:
        "201":
          description: OCR invoice job page created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/OcrInvoiceJobPage"
        "400":
          description: Bad request
        "401":
          description: Unauthorized
        "500":
          description: Internal server error

  /ocr-invoice-job-page/{id}:
    get:
      tags:
        - OCR Invoice Job Page
      summary: Get OCR invoice job page by ID
      description: Retrieve a specific OCR invoice job page by its ID
      parameters:
        - name: id
          in: path
          required: true
          description: OCR invoice job page ID
          schema:
            type: string
      responses:
        "200":
          description: OCR invoice job page retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/OcrInvoiceJobPage"
        "404":
          description: OCR invoice job page not found
        "401":
          description: Unauthorized
        "500":
          description: Internal server error
    put:
      tags:
        - OCR Invoice Job Page
      summary: Update OCR invoice job page
      description: Update an existing OCR invoice job page with new data
      parameters:
        - name: id
          in: path
          required: true
          description: OCR invoice job page ID
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/OcrInvoiceJobPageInput"
      responses:
        "200":
          description: OCR invoice job page updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/OcrInvoiceJobPage"
        "400":
          description: Bad request
        "404":
          description: OCR invoice job page not found
        "401":
          description: Unauthorized
        "500":
          description: Internal server error
    delete:
      tags:
        - OCR Invoice Job Page
      summary: Delete OCR invoice job page
      description: Delete an existing OCR invoice job page
      parameters:
        - name: id
          in: path
          required: true
          description: OCR invoice job page ID
          schema:
            type: string
      responses:
        "200":
          description: OCR invoice job page deleted successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: OCR invoice job page deleted successfully
        "404":
          description: OCR invoice job page not found
        "401":
          description: Unauthorized
        "500":
          description: Internal server error

  /ocr-invoice-job-page/{id}/process:
    post:
      tags:
        - OCR Invoice Job Page
      summary: Process OCR invoice job page
      description: Start processing a specific page of an OCR invoice job
      parameters:
        - name: id
          in: path
          required: true
          description: OCR invoice job page ID
          schema:
            type: string
      responses:
        "200":
          description: OCR invoice job page processing started
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      pageId:
                        type: string
                      status:
                        type: string
                        enum: [queued, processing]
        "404":
          description: OCR invoice job page not found
        "401":
          description: Unauthorized
        "500":
          description: Internal server error

components:
  schemas:
    OcrInvoiceJobPage:
      type: object
      properties:
        _id:
          type: string
          description: Unique identifier for the OCR invoice job page
          example: "60f7b1b3e4b0e8b3f8b3f8b3"
        job:
          type: string
          description: OCR invoice job ID this page belongs to
          example: "60f7b1b3e4b0e8b3f8b3f8b4"
        pageNumber:
          type: integer
          minimum: 1
          description: Page number within the document
          example: 1
        pageUrl:
          type: string
          format: uri
          description: URL of the page image
          example: "https://storage.example.com/pages/invoice_2023_001_page_1.png"
        status:
          type: string
          enum: [pending, processing, completed, failed, skipped]
          default: pending
          description: Processing status of this page
        pageType:
          type: string
          enum: [cover, header, content, footer, summary, attachment]
          description: Type of page content
          example: "content"
        imageProperties:
          type: object
          properties:
            width:
              type: integer
              description: Image width in pixels
            height:
              type: integer
              description: Image height in pixels
            dpi:
              type: integer
              description: Image resolution in DPI
            colorSpace:
              type: string
              enum: [rgb, grayscale, binary]
              description: Color space of the image
            format:
              type: string
              enum: [png, jpg, jpeg, tiff, bmp]
              description: Image format
            size:
              type: integer
              description: File size in bytes
        preprocessing:
          type: object
          properties:
            enhanced:
              type: boolean
              description: Whether image was enhanced
            deskewed:
              type: boolean
              description: Whether image was deskewed
            denoised:
              type: boolean
              description: Whether noise was removed
            binarized:
              type: boolean
              description: Whether image was binarized
            rotationAngle:
              type: number
              format: double
              description: Rotation angle applied
        ocrResults:
          type: object
          properties:
            text:
              type: string
              description: Raw OCR text output
            confidence:
              type: number
              format: double
              minimum: 0
              maximum: 1
              description: Overall OCR confidence for this page
            words:
              type: array
              items:
                type: object
                properties:
                  text:
                    type: string
                    description: Word text
                  confidence:
                    type: number
                    format: double
                    minimum: 0
                    maximum: 1
                    description: Word confidence
                  boundingBox:
                    type: object
                    properties:
                      x:
                        type: number
                        format: double
                      y:
                        type: number
                        format: double
                      width:
                        type: number
                        format: double
                      height:
                        type: number
                        format: double
            blocks:
              type: array
              items:
                type: object
                properties:
                  text:
                    type: string
                    description: Block text
                  confidence:
                    type: number
                    format: double
                  boundingBox:
                    type: object
                    properties:
                      x:
                        type: number
                        format: double
                      y:
                        type: number
                        format: double
                      width:
                        type: number
                        format: double
                      height:
                        type: number
                        format: double
                  blockType:
                    type: string
                    enum: [text, table, image, signature]
        extractedFields:
          type: object
          additionalProperties: true
          description: Fields extracted from this page
        tableData:
          type: array
          items:
            type: object
            properties:
              rowIndex:
                type: integer
              columnIndex:
                type: integer
              cellText:
                type: string
              confidence:
                type: number
                format: double
              boundingBox:
                type: object
                properties:
                  x:
                    type: number
                  y:
                    type: number
                  width:
                    type: number
                  height:
                    type: number
        processingTime:
          type: number
          format: double
          description: Processing time for this page in seconds
        startedAt:
          type: string
          format: date-time
          description: When page processing started
          example: "2023-01-15T08:00:00Z"
        completedAt:
          type: string
          format: date-time
          description: When page processing completed
          example: "2023-01-15T08:01:00Z"
        errorLog:
          type: string
          description: Error log if processing failed
        retryCount:
          type: integer
          minimum: 0
          description: Number of retry attempts
        qualityScore:
          type: number
          format: double
          minimum: 0
          maximum: 1
          description: Quality score of the page
        annotations:
          type: array
          items:
            type: object
            properties:
              type:
                type: string
                enum: [correction, highlight, note, region]
              text:
                type: string
              coordinates:
                type: object
                properties:
                  x:
                    type: number
                  y:
                    type: number
                  width:
                    type: number
                  height:
                    type: number
              createdBy:
                type: string
              createdAt:
                type: string
                format: date-time
        metadata:
          type: object
          additionalProperties: true
          description: Additional metadata
        createdAt:
          type: string
          format: date-time
          description: Record creation timestamp
          example: "2023-01-15T08:00:00Z"
        updatedAt:
          type: string
          format: date-time
          description: Record last update timestamp
          example: "2023-01-15T10:30:00Z"
      required:
        - job
        - pageNumber
        - pageUrl

    OcrInvoiceJobPageInput:
      type: object
      properties:
        job:
          type: string
          description: OCR invoice job ID this page belongs to
          example: "60f7b1b3e4b0e8b3f8b3f8b4"
        pageNumber:
          type: integer
          minimum: 1
          description: Page number within the document
          example: 1
        pageUrl:
          type: string
          format: uri
          description: URL of the page image
          example: "https://storage.example.com/pages/invoice_2023_001_page_1.png"
        pageType:
          type: string
          enum: [cover, header, content, footer, summary, attachment]
          description: Type of page content
          example: "content"
        imageProperties:
          type: object
          properties:
            width:
              type: integer
              description: Image width in pixels
            height:
              type: integer
              description: Image height in pixels
            dpi:
              type: integer
              description: Image resolution in DPI
            colorSpace:
              type: string
              enum: [rgb, grayscale, binary]
              description: Color space of the image
            format:
              type: string
              enum: [png, jpg, jpeg, tiff, bmp]
              description: Image format
            size:
              type: integer
              description: File size in bytes
        annotations:
          type: array
          items:
            type: object
            properties:
              type:
                type: string
                enum: [correction, highlight, note, region]
              text:
                type: string
              coordinates:
                type: object
                properties:
                  x:
                    type: number
                  y:
                    type: number
                  width:
                    type: number
                  height:
                    type: number
              createdBy:
                type: string
              createdAt:
                type: string
                format: date-time
        metadata:
          type: object
          additionalProperties: true
          description: Additional metadata
      required:
        - job
        - pageNumber
        - pageUrl

  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: api-key

security:
  - ApiKeyAuth: []
