openapi: 3.0.0
info:
  title: Workorder Category API
  description: API for managing workorder categories
  version: 1.0.0
servers:
  - url: https://api.repzo.me/v1
    description: Production server
security:
  - ApiKeyAuth: []
tags:
  - name: Workorder Category
    description: Workorder category management operations
paths:
  /workorder-category:
    get:
      tags:
        - Workorder Category
      summary: Get all workorder categories
      description: Retrieve a list of all workorder categories with optional filtering and pagination
      parameters:
        - name: page
          in: query
          description: Page number for pagination
          required: false
          schema:
            type: integer
            minimum: 1
            default: 1
        - name: per_page
          in: query
          description: Number of items per page
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 25
        - name: sort
          in: query
          description: Sort field
          required: false
          schema:
            type: string
        - name: company_namespace
          in: query
          description: Company namespace for filtering
          required: false
          schema:
            type: array
            items:
              type: string
        - name: disabled
          in: query
          description: Filter by disabled status
          required: false
          schema:
            type: boolean
        - name: parent_category
          in: query
          description: Filter by parent category ID
          required: false
          schema:
            type: string
        - name: _id
          in: query
          description: Filter by ID
          required: false
          schema:
            type: array
            items:
              type: string
      responses:
        "200":
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/WorkorderCategory"
                  paging:
                    $ref: "#/components/schemas/PagingInfo"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "500":
          $ref: "#/components/responses/InternalServerError"
    post:
      tags:
        - Workorder Category
      summary: Create a new workorder category
      description: Create a new workorder category
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateWorkorderCategoryRequest"
      responses:
        "201":
          description: Workorder category created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/WorkorderCategory"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "422":
          $ref: "#/components/responses/ValidationError"
        "500":
          $ref: "#/components/responses/InternalServerError"
  /workorder-category/{id}:
    get:
      tags:
        - Workorder Category
      summary: Get workorder category by ID
      description: Retrieve a specific workorder category by its ID
      parameters:
        - name: id
          in: path
          required: true
          description: Workorder category ID
          schema:
            type: string
      responses:
        "200":
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/WorkorderCategory"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "500":
          $ref: "#/components/responses/InternalServerError"
    patch:
      tags:
        - Workorder Category
      summary: Update workorder category
      description: Update an existing workorder category
      parameters:
        - name: id
          in: path
          required: true
          description: Workorder category ID
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/UpdateWorkorderCategoryRequest"
      responses:
        "200":
          description: Workorder category updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/WorkorderCategory"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "422":
          $ref: "#/components/responses/ValidationError"
        "500":
          $ref: "#/components/responses/InternalServerError"
    delete:
      tags:
        - Workorder Category
      summary: Delete workorder category
      description: Delete a workorder category by ID
      parameters:
        - name: id
          in: path
          required: true
          description: Workorder category ID
          schema:
            type: string
      responses:
        "200":
          description: Workorder category deleted successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "500":
          $ref: "#/components/responses/InternalServerError"
  /workorder-category/remove:
    post:
      tags:
        - Workorder Category
      summary: Bulk delete workorder categories
      description: Delete multiple workorder categories by their IDs
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                ids:
                  type: array
                  items:
                    type: string
                  description: Array of workorder category IDs to delete
              required:
                - ids
      responses:
        "200":
          description: Workorder categories deleted successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "500":
          $ref: "#/components/responses/InternalServerError"
  /workorder-category/hierarchy:
    get:
      tags:
        - Workorder Category
      summary: Get category hierarchy
      description: Get workorder categories in hierarchical structure
      responses:
        "200":
          description: Category hierarchy retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/WorkorderCategoryHierarchy"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "500":
          $ref: "#/components/responses/InternalServerError"
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: "Use format: Bearer {api_key}"
  schemas:
    WorkorderCategory:
      type: object
      properties:
        _id:
          type: string
          description: Unique identifier
          example: "507f1f77bcf86cd799439011"
        name:
          type: string
          description: Category name
          example: "Maintenance"
        description:
          type: string
          description: Category description
          example: "General maintenance workorders"
        code:
          type: string
          description: Category code for identification
          example: "MAINT"
        parent_category:
          type: string
          description: Parent category ID for hierarchical structure
          example: "507f1f77bcf86cd799439012"
        color:
          type: string
          description: Color code for visual identification
          example: "#FF5733"
        icon:
          type: string
          description: Icon identifier
          example: "wrench"
        priority_level:
          type: integer
          description: Default priority level for workorders in this category
          minimum: 1
          maximum: 5
          example: 3
        estimated_duration:
          type: integer
          description: Estimated duration in minutes
          example: 120
        required_skills:
          type: array
          items:
            type: string
          description: Skills required for this category
          example: ["electrical", "plumbing"]
        default_assignee:
          type: string
          description: Default assignee for this category
          example: "507f1f77bcf86cd799439013"
        notification_settings:
          type: object
          properties:
            notify_on_creation:
              type: boolean
              description: Send notification when workorder is created
            notify_on_completion:
              type: boolean
              description: Send notification when workorder is completed
            escalation_time:
              type: integer
              description: Time in hours before escalation
        approval_required:
          type: boolean
          description: Whether approval is required for workorders in this category
          example: false
        custom_fields:
          type: array
          items:
            type: object
            properties:
              field_name:
                type: string
              field_type:
                type: string
                enum: ["text", "number", "date", "select", "checkbox"]
              is_required:
                type: boolean
              options:
                type: array
                items:
                  type: string
          description: Custom fields for this category
        sla_settings:
          type: object
          properties:
            response_time:
              type: integer
              description: Response time in hours
            resolution_time:
              type: integer
              description: Resolution time in hours
            business_hours_only:
              type: boolean
              description: Whether SLA applies only to business hours
        sort_order:
          type: integer
          description: Sort order for display
          example: 1
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespace
        disabled:
          type: boolean
          description: Whether the category is disabled
          example: false
        createdAt:
          type: string
          format: date-time
          description: Creation timestamp
        modifiedAt:
          type: string
          format: date-time
          description: Last modification timestamp
        SVClient:
          type: integer
          description: Client version
        __v:
          type: integer
          description: Document version
      required:
        - name
    WorkorderCategoryHierarchy:
      type: object
      properties:
        _id:
          type: string
          description: Category ID
        name:
          type: string
          description: Category name
        description:
          type: string
          description: Category description
        code:
          type: string
          description: Category code
        color:
          type: string
          description: Color code
        icon:
          type: string
          description: Icon identifier
        children:
          type: array
          items:
            $ref: "#/components/schemas/WorkorderCategoryHierarchy"
          description: Child categories
        workorder_count:
          type: integer
          description: Number of workorders in this category
    CreateWorkorderCategoryRequest:
      type: object
      properties:
        name:
          type: string
          description: Category name
          example: "Maintenance"
        description:
          type: string
          description: Category description
          example: "General maintenance workorders"
        code:
          type: string
          description: Category code for identification
          example: "MAINT"
        parent_category:
          type: string
          description: Parent category ID for hierarchical structure
        color:
          type: string
          description: Color code for visual identification
          example: "#FF5733"
        icon:
          type: string
          description: Icon identifier
          example: "wrench"
        priority_level:
          type: integer
          description: Default priority level for workorders in this category
          minimum: 1
          maximum: 5
          default: 3
        estimated_duration:
          type: integer
          description: Estimated duration in minutes
        required_skills:
          type: array
          items:
            type: string
          description: Skills required for this category
        default_assignee:
          type: string
          description: Default assignee for this category
        notification_settings:
          type: object
          properties:
            notify_on_creation:
              type: boolean
              default: true
            notify_on_completion:
              type: boolean
              default: true
            escalation_time:
              type: integer
        approval_required:
          type: boolean
          description: Whether approval is required for workorders in this category
          default: false
        custom_fields:
          type: array
          items:
            type: object
            properties:
              field_name:
                type: string
              field_type:
                type: string
                enum: ["text", "number", "date", "select", "checkbox"]
              is_required:
                type: boolean
              options:
                type: array
                items:
                  type: string
        sla_settings:
          type: object
          properties:
            response_time:
              type: integer
            resolution_time:
              type: integer
            business_hours_only:
              type: boolean
              default: true
        sort_order:
          type: integer
          description: Sort order for display
          default: 0
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespace
        disabled:
          type: boolean
          description: Whether the category is disabled
          default: false
      required:
        - name
    UpdateWorkorderCategoryRequest:
      type: object
      properties:
        name:
          type: string
          description: Category name
        description:
          type: string
          description: Category description
        code:
          type: string
          description: Category code for identification
        parent_category:
          type: string
          description: Parent category ID for hierarchical structure
        color:
          type: string
          description: Color code for visual identification
        icon:
          type: string
          description: Icon identifier
        priority_level:
          type: integer
          description: Default priority level for workorders in this category
          minimum: 1
          maximum: 5
        estimated_duration:
          type: integer
          description: Estimated duration in minutes
        required_skills:
          type: array
          items:
            type: string
          description: Skills required for this category
        default_assignee:
          type: string
          description: Default assignee for this category
        notification_settings:
          type: object
          properties:
            notify_on_creation:
              type: boolean
            notify_on_completion:
              type: boolean
            escalation_time:
              type: integer
        approval_required:
          type: boolean
          description: Whether approval is required for workorders in this category
        custom_fields:
          type: array
          items:
            type: object
            properties:
              field_name:
                type: string
              field_type:
                type: string
                enum: ["text", "number", "date", "select", "checkbox"]
              is_required:
                type: boolean
              options:
                type: array
                items:
                  type: string
        sla_settings:
          type: object
          properties:
            response_time:
              type: integer
            resolution_time:
              type: integer
            business_hours_only:
              type: boolean
        sort_order:
          type: integer
          description: Sort order for display
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespace
        disabled:
          type: boolean
          description: Whether the category is disabled
    PagingInfo:
      type: object
      properties:
        total:
          type: integer
          description: Total number of items
        page:
          type: integer
          description: Current page number
        per_page:
          type: integer
          description: Items per page
        pages:
          type: integer
          description: Total number of pages
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Invalid request parameters"
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Authentication required"
    Forbidden:
      description: Forbidden
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Insufficient permissions"
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Resource not found"
    ValidationError:
      description: Validation error
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Validation failed"
    InternalServerError:
      description: Internal server error
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Internal server error"
