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

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

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

  /ocr-invoice-job-group/{id}/jobs:
    get:
      tags:
        - OCR Invoice Job Group
      summary: Get jobs in a group
      description: Retrieve all OCR jobs belonging to a specific group
      parameters:
        - name: id
          in: path
          required: true
          description: OCR invoice job group ID
          schema:
            type: string
      responses:
        "200":
          description: OCR jobs in group retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        jobId:
                          type: string
                        status:
                          type: string
                        documentName:
                          type: string
        "404":
          description: OCR invoice job group not found
        "401":
          description: Unauthorized
        "500":
          description: Internal server error

components:
  schemas:
    OcrInvoiceJobGroup:
      type: object
      properties:
        _id:
          type: string
          description: Unique identifier for the OCR invoice job group
          example: "60f7b1b3e4b0e8b3f8b3f8b3"
        name:
          type: string
          description: Name of the job group
          example: "Monthly Invoice Batch - January 2023"
        description:
          type: string
          description: Description of the job group
        batchNumber:
          type: string
          description: Batch number for tracking
          example: "BATCH-2023-001"
        template:
          type: string
          description: OCR template ID to use for this group
          example: "60f7b1b3e4b0e8b3f8b3f8b4"
        totalJobs:
          type: integer
          minimum: 0
          description: Total number of jobs in the group
          example: 150
        completedJobs:
          type: integer
          minimum: 0
          description: Number of completed jobs
          example: 120
        pendingJobs:
          type: integer
          minimum: 0
          description: Number of pending jobs
          example: 20
        failedJobs:
          type: integer
          minimum: 0
          description: Number of failed jobs
          example: 10
        status:
          type: string
          enum: [created, queued, processing, completed, failed, cancelled]
          default: created
          description: Overall status of the job group
        priority:
          type: string
          enum: [low, medium, high, urgent]
          default: medium
          description: Processing priority
        startedAt:
          type: string
          format: date-time
          description: When processing started
          example: "2023-01-15T08:00:00Z"
        completedAt:
          type: string
          format: date-time
          description: When processing completed
          example: "2023-01-15T10:30:00Z"
        estimatedCompletionTime:
          type: string
          format: date-time
          description: Estimated completion time
          example: "2023-01-15T11:00:00Z"
        processingSettings:
          type: object
          properties:
            parallelJobs:
              type: integer
              minimum: 1
              maximum: 10
              default: 3
              description: Number of parallel jobs to process
            retryCount:
              type: integer
              minimum: 0
              maximum: 5
              default: 2
              description: Number of retry attempts for failed jobs
            timeoutMinutes:
              type: integer
              minimum: 5
              maximum: 120
              default: 30
              description: Timeout for each job in minutes
        statistics:
          type: object
          properties:
            totalDocuments:
              type: integer
              description: Total number of documents processed
            totalPages:
              type: integer
              description: Total number of pages processed
            averageProcessingTime:
              type: number
              format: double
              description: Average processing time per document in seconds
            successRate:
              type: number
              format: double
              minimum: 0
              maximum: 1
              description: Success rate as percentage
            totalCost:
              type: number
              format: double
              minimum: 0
              description: Total processing cost
            currency:
              type: string
              example: "USD"
        notifications:
          type: object
          properties:
            onCompletion:
              type: boolean
              default: false
              description: Send notification on completion
            onFailure:
              type: boolean
              default: true
              description: Send notification on failure
            recipients:
              type: array
              items:
                type: string
                format: email
              description: Email recipients for notifications
        createdBy:
          type: string
          description: User who created the job group
          example: "60f7b1b3e4b0e8b3f8b3f8b5"
        assignedTo:
          type: string
          description: User assigned to manage this group
          example: "60f7b1b3e4b0e8b3f8b3f8b6"
        tags:
          type: array
          items:
            type: string
          description: Tags for categorization
          example: ["monthly", "invoices", "accounting"]
        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
        - template

    OcrInvoiceJobGroupInput:
      type: object
      properties:
        name:
          type: string
          description: Name of the job group
          example: "Monthly Invoice Batch - January 2023"
        description:
          type: string
          description: Description of the job group
        batchNumber:
          type: string
          description: Batch number for tracking
          example: "BATCH-2023-001"
        template:
          type: string
          description: OCR template ID to use for this group
          example: "60f7b1b3e4b0e8b3f8b3f8b4"
        priority:
          type: string
          enum: [low, medium, high, urgent]
          default: medium
          description: Processing priority
        processingSettings:
          type: object
          properties:
            parallelJobs:
              type: integer
              minimum: 1
              maximum: 10
              default: 3
              description: Number of parallel jobs to process
            retryCount:
              type: integer
              minimum: 0
              maximum: 5
              default: 2
              description: Number of retry attempts for failed jobs
            timeoutMinutes:
              type: integer
              minimum: 5
              maximum: 120
              default: 30
              description: Timeout for each job in minutes
        notifications:
          type: object
          properties:
            onCompletion:
              type: boolean
              default: false
              description: Send notification on completion
            onFailure:
              type: boolean
              default: true
              description: Send notification on failure
            recipients:
              type: array
              items:
                type: string
                format: email
              description: Email recipients for notifications
        createdBy:
          type: string
          description: User who created the job group
          example: "60f7b1b3e4b0e8b3f8b3f8b5"
        assignedTo:
          type: string
          description: User assigned to manage this group
          example: "60f7b1b3e4b0e8b3f8b3f8b6"
        tags:
          type: array
          items:
            type: string
          description: Tags for categorization
          example: ["monthly", "invoices", "accounting"]
        metadata:
          type: object
          additionalProperties: true
          description: Additional metadata
      required:
        - name
        - template

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

security:
  - ApiKeyAuth: []
