openapi: 3.0.0
info:
  title: OCR Invoice Job Template API
  description: API for managing OCR invoice job templates
  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 Template
    description: Operations related to OCR invoice job template management

paths:
  /ocr-invoice-job-template:
    get:
      tags:
        - OCR Invoice Job Template
      summary: Get all OCR invoice job templates
      description: Retrieve a list of all OCR invoice job templates 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 templates retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/OcrInvoiceJobTemplate"
                  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 Template
      summary: Create a new OCR invoice job template
      description: Create a new OCR invoice job template with the provided data
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/OcrInvoiceJobTemplateInput"
      responses:
        "201":
          description: OCR invoice job template created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/OcrInvoiceJobTemplate"
        "400":
          description: Bad request
        "401":
          description: Unauthorized
        "500":
          description: Internal server error

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

components:
  schemas:
    OcrInvoiceJobTemplate:
      type: object
      properties:
        _id:
          type: string
          description: Unique identifier for the OCR invoice job template
          example: "60f7b1b3e4b0e8b3f8b3f8b3"
        name:
          type: string
          description: Name of the template
          example: "Standard Invoice OCR Template"
        description:
          type: string
          description: Description of the template
        version:
          type: string
          description: Template version
          example: "1.0.0"
        ocrEngine:
          type: string
          enum:
            [tesseract, google-vision, aws-textract, azure-cognitive, custom]
          description: OCR engine to use
          example: "google-vision"
        documentType:
          type: string
          enum: [invoice, receipt, bill, statement, other]
          description: Type of document
          example: "invoice"
        extractionRules:
          type: object
          properties:
            fields:
              type: array
              items:
                type: object
                properties:
                  name:
                    type: string
                    description: Field name
                  type:
                    type: string
                    enum: [text, number, date, currency, boolean]
                    description: Data type
                  required:
                    type: boolean
                    description: Whether field is required
                  pattern:
                    type: string
                    description: Regex pattern for extraction
                  coordinates:
                    type: object
                    properties:
                      x:
                        type: number
                      y:
                        type: number
                      width:
                        type: number
                      height:
                        type: number
                  validation:
                    type: object
                    properties:
                      minLength:
                        type: integer
                      maxLength:
                        type: integer
                      format:
                        type: string
            lineItems:
              type: object
              properties:
                enabled:
                  type: boolean
                  description: Whether to extract line items
                tableStructure:
                  type: object
                  properties:
                    headerRow:
                      type: integer
                      description: Header row number
                    dataStartRow:
                      type: integer
                      description: Data start row number
                    columns:
                      type: array
                      items:
                        type: object
                        properties:
                          name:
                            type: string
                          index:
                            type: integer
                          type:
                            type: string
                            enum: [text, number, currency]
        preprocessingSettings:
          type: object
          properties:
            imageEnhancement:
              type: boolean
              default: true
              description: Whether to enhance image quality
            deskew:
              type: boolean
              default: true
              description: Whether to correct image skew
            denoising:
              type: boolean
              default: true
              description: Whether to remove noise
            binarization:
              type: boolean
              default: false
              description: Whether to convert to binary image
            resolutionDPI:
              type: integer
              minimum: 150
              maximum: 600
              default: 300
              description: Target resolution in DPI
        postprocessingSettings:
          type: object
          properties:
            spellCheck:
              type: boolean
              default: false
              description: Whether to perform spell checking
            confidenceThreshold:
              type: number
              format: double
              minimum: 0
              maximum: 1
              default: 0.8
              description: Minimum confidence threshold
            validationRules:
              type: array
              items:
                type: object
                properties:
                  field:
                    type: string
                  rule:
                    type: string
                    enum: [required, numeric, date, email, currency]
                  message:
                    type: string
        supportedFormats:
          type: array
          items:
            type: string
            enum: [pdf, png, jpg, jpeg, tiff, bmp]
          description: Supported document formats
        languages:
          type: array
          items:
            type: string
          description: Supported languages for OCR
          example: ["en", "es", "fr"]
        accuracy:
          type: object
          properties:
            averageAccuracy:
              type: number
              format: double
              minimum: 0
              maximum: 1
              description: Average accuracy percentage
            fieldAccuracy:
              type: object
              additionalProperties:
                type: number
                format: double
              description: Accuracy per field
        isActive:
          type: boolean
          default: true
          description: Whether the template is active
        isDefault:
          type: boolean
          default: false
          description: Whether this is the default template
        createdBy:
          type: string
          description: User who created the template
        lastModifiedBy:
          type: string
          description: User who last modified the template
        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:
        - name
        - ocrEngine
        - documentType
        - extractionRules

    OcrInvoiceJobTemplateInput:
      type: object
      properties:
        name:
          type: string
          description: Name of the template
          example: "Standard Invoice OCR Template"
        description:
          type: string
          description: Description of the template
        version:
          type: string
          description: Template version
          example: "1.0.0"
        ocrEngine:
          type: string
          enum:
            [tesseract, google-vision, aws-textract, azure-cognitive, custom]
          description: OCR engine to use
          example: "google-vision"
        documentType:
          type: string
          enum: [invoice, receipt, bill, statement, other]
          description: Type of document
          example: "invoice"
        extractionRules:
          type: object
          properties:
            fields:
              type: array
              items:
                type: object
                properties:
                  name:
                    type: string
                    description: Field name
                  type:
                    type: string
                    enum: [text, number, date, currency, boolean]
                    description: Data type
                  required:
                    type: boolean
                    description: Whether field is required
                  pattern:
                    type: string
                    description: Regex pattern for extraction
                  coordinates:
                    type: object
                    properties:
                      x:
                        type: number
                      y:
                        type: number
                      width:
                        type: number
                      height:
                        type: number
                  validation:
                    type: object
                    properties:
                      minLength:
                        type: integer
                      maxLength:
                        type: integer
                      format:
                        type: string
            lineItems:
              type: object
              properties:
                enabled:
                  type: boolean
                  description: Whether to extract line items
                tableStructure:
                  type: object
                  properties:
                    headerRow:
                      type: integer
                      description: Header row number
                    dataStartRow:
                      type: integer
                      description: Data start row number
                    columns:
                      type: array
                      items:
                        type: object
                        properties:
                          name:
                            type: string
                          index:
                            type: integer
                          type:
                            type: string
                            enum: [text, number, currency]
        preprocessingSettings:
          type: object
          properties:
            imageEnhancement:
              type: boolean
              default: true
              description: Whether to enhance image quality
            deskew:
              type: boolean
              default: true
              description: Whether to correct image skew
            denoising:
              type: boolean
              default: true
              description: Whether to remove noise
            binarization:
              type: boolean
              default: false
              description: Whether to convert to binary image
            resolutionDPI:
              type: integer
              minimum: 150
              maximum: 600
              default: 300
              description: Target resolution in DPI
        postprocessingSettings:
          type: object
          properties:
            spellCheck:
              type: boolean
              default: false
              description: Whether to perform spell checking
            confidenceThreshold:
              type: number
              format: double
              minimum: 0
              maximum: 1
              default: 0.8
              description: Minimum confidence threshold
            validationRules:
              type: array
              items:
                type: object
                properties:
                  field:
                    type: string
                  rule:
                    type: string
                    enum: [required, numeric, date, email, currency]
                  message:
                    type: string
        supportedFormats:
          type: array
          items:
            type: string
            enum: [pdf, png, jpg, jpeg, tiff, bmp]
          description: Supported document formats
        languages:
          type: array
          items:
            type: string
          description: Supported languages for OCR
          example: ["en", "es", "fr"]
        isActive:
          type: boolean
          default: true
          description: Whether the template is active
        isDefault:
          type: boolean
          default: false
          description: Whether this is the default template
        createdBy:
          type: string
          description: User who created the template
        lastModifiedBy:
          type: string
          description: User who last modified the template
        metadata:
          type: object
          additionalProperties: true
          description: Additional metadata
      required:
        - name
        - ocrEngine
        - documentType
        - extractionRules

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

security:
  - ApiKeyAuth: []
