openapi: 3.0.0
info:
  title: Patch Action API
  description: API for managing patch actions
  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: Patch Action
    description: Operations related to patch action management

paths:
  /patch-action:
    get:
      tags:
        - Patch Action
      summary: Get all patch action records
      description: Retrieve a list of all patch action records 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 patch action records retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/PatchAction"
                  total:
                    type: integer
                    description: Total number of records
        "400":
          description: Bad request
        "401":
          description: Unauthorized
        "500":
          description: Internal server error
    post:
      tags:
        - Patch Action
      summary: Create a new patch action
      description: Create a new patch action with the provided data
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/PatchActionInput"
      responses:
        "201":
          description: Patch action created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/PatchAction"
        "400":
          description: Bad request
        "401":
          description: Unauthorized
        "500":
          description: Internal server error

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

  /patch-action/execute/{id}:
    post:
      tags:
        - Patch Action
      summary: Execute patch action
      description: Execute a specific patch action by its ID
      parameters:
        - name: id
          in: path
          required: true
          description: Patch action ID
          schema:
            type: string
      responses:
        "200":
          description: Patch action executed successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      executionId:
                        type: string
                        description: Execution ID for tracking
                      status:
                        type: string
                        enum: [queued, running, completed, failed]
        "404":
          description: Patch action not found
        "401":
          description: Unauthorized
        "500":
          description: Internal server error

components:
  schemas:
    PatchAction:
      type: object
      properties:
        _id:
          type: string
          description: Unique identifier for the patch action
          example: "60f7b1b3e4b0e8b3f8b3f8b3"
        name:
          type: string
          description: Name of the patch action
          example: "Update Product Prices"
        description:
          type: string
          description: Description of what the patch action does
        targetEntity:
          type: string
          description: The entity type this patch targets
          example: "product"
        conditions:
          type: object
          additionalProperties: true
          description: Conditions that must be met for the patch to apply
        patches:
          type: array
          items:
            type: object
            properties:
              field:
                type: string
                description: Field to patch
              operation:
                type: string
                enum: [set, unset, add, remove, multiply, divide]
                description: Operation to perform
              value:
                description: Value for the operation
        batchSize:
          type: integer
          minimum: 1
          maximum: 1000
          default: 100
          description: Number of records to process in each batch
        status:
          type: string
          enum: [draft, ready, running, completed, failed, cancelled]
          default: draft
          description: Status of the patch action
        executionHistory:
          type: array
          items:
            type: object
            properties:
              executionId:
                type: string
              startTime:
                type: string
                format: date-time
              endTime:
                type: string
                format: date-time
              status:
                type: string
                enum: [running, completed, failed, cancelled]
              processedCount:
                type: integer
              errorCount:
                type: integer
              errors:
                type: array
                items:
                  type: string
        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
        - targetEntity
        - patches

    PatchActionInput:
      type: object
      properties:
        name:
          type: string
          description: Name of the patch action
          example: "Update Product Prices"
        description:
          type: string
          description: Description of what the patch action does
        targetEntity:
          type: string
          description: The entity type this patch targets
          example: "product"
        conditions:
          type: object
          additionalProperties: true
          description: Conditions that must be met for the patch to apply
        patches:
          type: array
          items:
            type: object
            properties:
              field:
                type: string
                description: Field to patch
              operation:
                type: string
                enum: [set, unset, add, remove, multiply, divide]
                description: Operation to perform
              value:
                description: Value for the operation
        batchSize:
          type: integer
          minimum: 1
          maximum: 1000
          default: 100
          description: Number of records to process in each batch
        status:
          type: string
          enum: [draft, ready, running, completed, failed, cancelled]
          default: draft
          description: Status of the patch action
        metadata:
          type: object
          additionalProperties: true
          description: Additional metadata
      required:
        - name
        - targetEntity
        - patches

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

security:
  - ApiKeyAuth: []
