openapi: 3.0.0
info:
  title: Feedback Options API
  description: API for managing feedback options and templates
  version: 1.0.0
servers:
  - url: https://api.repzo.me/v1
    description: Production server
security:
  - ApiKeyAuth: []
tags:
  - name: Feedback Options
    description: Feedback options management operations
paths:
  /feedback-options:
    get:
      tags:
        - Feedback Options
      summary: Get all feedback options
      description: Retrieve a list of all feedback options 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: category
          in: query
          description: Filter by category
          required: false
          schema:
            type: string
        - name: is_active
          in: query
          description: Filter by active status
          required: false
          schema:
            type: boolean
        - name: template_type
          in: query
          description: Filter by template type
          required: false
          schema:
            type: string
            enum: ["survey", "rating", "nps", "custom"]
        - 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/FeedbackOptions"
                  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:
        - Feedback Options
      summary: Create new feedback options
      description: Create a new feedback options template
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateFeedbackOptionsRequest"
      responses:
        "201":
          description: Feedback options created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/FeedbackOptions"
        "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"
  /feedback-options/{id}:
    get:
      tags:
        - Feedback Options
      summary: Get feedback options by ID
      description: Retrieve a specific feedback options template by its ID
      parameters:
        - name: id
          in: path
          required: true
          description: Feedback options 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/FeedbackOptions"
        "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:
        - Feedback Options
      summary: Update feedback options
      description: Update an existing feedback options template
      parameters:
        - name: id
          in: path
          required: true
          description: Feedback options ID
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/UpdateFeedbackOptionsRequest"
      responses:
        "200":
          description: Feedback options updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/FeedbackOptions"
        "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:
        - Feedback Options
      summary: Delete feedback options
      description: Delete a feedback options template by ID
      parameters:
        - name: id
          in: path
          required: true
          description: Feedback options ID
          schema:
            type: string
      responses:
        "200":
          description: Feedback options 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"
  /feedback-options/{id}/preview:
    get:
      tags:
        - Feedback Options
      summary: Preview feedback template
      description: Get a preview of how the feedback template will appear
      parameters:
        - name: id
          in: path
          required: true
          description: Feedback options ID
          schema:
            type: string
      responses:
        "200":
          description: Template preview retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      template_html:
                        type: string
                        description: HTML preview of the template
                      estimated_completion_time:
                        type: integer
                        description: Estimated time to complete in seconds
                      question_count:
                        type: integer
                        description: Total number of questions
        "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"
  /feedback-options/templates:
    get:
      tags:
        - Feedback Options
      summary: Get predefined templates
      description: Get a list of predefined feedback templates
      parameters:
        - name: category
          in: query
          description: Filter by category
          required: false
          schema:
            type: string
        - name: template_type
          in: query
          description: Filter by template type
          required: false
          schema:
            type: string
            enum: ["survey", "rating", "nps", "custom"]
      responses:
        "200":
          description: Predefined templates retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        template_id:
                          type: string
                        name:
                          type: string
                        description:
                          type: string
                        category:
                          type: string
                        template_type:
                          type: string
                        question_count:
                          type: integer
                        estimated_time:
                          type: integer
        "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:
    FeedbackOptions:
      type: object
      properties:
        _id:
          type: string
          description: Unique identifier
          example: "507f1f77bcf86cd799439011"
        name:
          type: string
          description: Template name
          example: "Sales Visit Feedback"
        description:
          type: string
          description: Template description
          example: "Feedback template for sales visit activities"
        category:
          type: string
          description: Category of the template
          example: "sales"
        template_type:
          type: string
          description: Type of feedback template
          enum: ["survey", "rating", "nps", "custom"]
          example: "survey"
        questions:
          type: array
          items:
            $ref: "#/components/schemas/FeedbackQuestion"
          description: List of questions in the template
        settings:
          type: object
          properties:
            allow_anonymous:
              type: boolean
              description: Allow anonymous feedback
              default: true
            require_all_questions:
              type: boolean
              description: Require all questions to be answered
              default: false
            show_progress:
              type: boolean
              description: Show progress indicator
              default: true
            randomize_questions:
              type: boolean
              description: Randomize question order
              default: false
            max_completion_time:
              type: integer
              description: Maximum time to complete in minutes
            reminder_settings:
              type: object
              properties:
                send_reminders:
                  type: boolean
                reminder_intervals:
                  type: array
                  items:
                    type: integer
                  description: Reminder intervals in hours
        styling:
          type: object
          properties:
            theme:
              type: string
              enum: ["light", "dark", "custom"]
              default: "light"
            primary_color:
              type: string
              description: Primary color hex code
              example: "#007bff"
            font_family:
              type: string
              description: Font family
              example: "Arial, sans-serif"
            custom_css:
              type: string
              description: Custom CSS styles
        notification_settings:
          type: object
          properties:
            notify_on_completion:
              type: boolean
              description: Send notification when feedback is completed
            notify_on_low_rating:
              type: boolean
              description: Send notification for low ratings
            low_rating_threshold:
              type: integer
              description: Threshold for low rating notifications
              minimum: 1
              maximum: 10
            notification_recipients:
              type: array
              items:
                type: string
              description: Email addresses to notify
        is_active:
          type: boolean
          description: Whether the template is active
          example: true
        usage_count:
          type: integer
          description: Number of times template has been used
          example: 25
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespace
        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
        - template_type
        - questions
    FeedbackQuestion:
      type: object
      properties:
        question_id:
          type: string
          description: Unique question identifier
        question_text:
          type: string
          description: The question text
          example: "How satisfied were you with the service?"
        question_type:
          type: string
          description: Type of question
          enum: ["rating", "multiple_choice", "text", "yes_no", "scale", "nps"]
          example: "rating"
        is_required:
          type: boolean
          description: Whether the question is required
          default: false
        options:
          type: array
          items:
            type: object
            properties:
              value:
                type: string
              label:
                type: string
              weight:
                type: number
                format: float
          description: Options for multiple choice questions
        validation:
          type: object
          properties:
            min_length:
              type: integer
            max_length:
              type: integer
            pattern:
              type: string
            custom_validation:
              type: string
        display_settings:
          type: object
          properties:
            show_labels:
              type: boolean
            orientation:
              type: string
              enum: ["horizontal", "vertical"]
            scale_min:
              type: integer
            scale_max:
              type: integer
            scale_step:
              type: integer
        conditional_logic:
          type: object
          properties:
            show_if:
              type: object
              properties:
                question_id:
                  type: string
                operator:
                  type: string
                  enum: ["equals", "not_equals", "greater_than", "less_than"]
                value:
                  oneOf:
                    - type: string
                    - type: integer
                    - type: boolean
      required:
        - question_text
        - question_type
    CreateFeedbackOptionsRequest:
      type: object
      properties:
        name:
          type: string
          description: Template name
          example: "Sales Visit Feedback"
        description:
          type: string
          description: Template description
        category:
          type: string
          description: Category of the template
        template_type:
          type: string
          description: Type of feedback template
          enum: ["survey", "rating", "nps", "custom"]
        questions:
          type: array
          items:
            $ref: "#/components/schemas/FeedbackQuestion"
        settings:
          type: object
          properties:
            allow_anonymous:
              type: boolean
              default: true
            require_all_questions:
              type: boolean
              default: false
            show_progress:
              type: boolean
              default: true
            randomize_questions:
              type: boolean
              default: false
            max_completion_time:
              type: integer
        styling:
          type: object
          properties:
            theme:
              type: string
              enum: ["light", "dark", "custom"]
              default: "light"
            primary_color:
              type: string
            font_family:
              type: string
            custom_css:
              type: string
        notification_settings:
          type: object
          properties:
            notify_on_completion:
              type: boolean
              default: false
            notify_on_low_rating:
              type: boolean
              default: false
            low_rating_threshold:
              type: integer
            notification_recipients:
              type: array
              items:
                type: string
        is_active:
          type: boolean
          description: Whether the template is active
          default: true
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespace
      required:
        - name
        - template_type
        - questions
    UpdateFeedbackOptionsRequest:
      type: object
      properties:
        name:
          type: string
          description: Template name
        description:
          type: string
          description: Template description
        category:
          type: string
          description: Category of the template
        questions:
          type: array
          items:
            $ref: "#/components/schemas/FeedbackQuestion"
        settings:
          type: object
          properties:
            allow_anonymous:
              type: boolean
            require_all_questions:
              type: boolean
            show_progress:
              type: boolean
            randomize_questions:
              type: boolean
            max_completion_time:
              type: integer
        styling:
          type: object
          properties:
            theme:
              type: string
              enum: ["light", "dark", "custom"]
            primary_color:
              type: string
            font_family:
              type: string
            custom_css:
              type: string
        notification_settings:
          type: object
          properties:
            notify_on_completion:
              type: boolean
            notify_on_low_rating:
              type: boolean
            low_rating_threshold:
              type: integer
            notification_recipients:
              type: array
              items:
                type: string
        is_active:
          type: boolean
          description: Whether the template is active
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespace
    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"
