openapi: 3.0.3
info:
  title: Repzo API - Settings
  version: 1.0.0
  description: OpenAPI specification for Repzo Settings endpoints.
servers:
  - url: https://sv.api.repzo.me
paths:
  /settings:
    get:
      summary: Find settings
      operationId: findSettings
      parameters:
        - in: query
          name: params
          schema:
            type: object
          description: Query parameters for filtering settings
      responses:
        "200":
          description: A list of settings
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SettingsFindResult"
  /settings/{id}:
    get:
      summary: Get settings by ID
      operationId: getSettings
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Settings details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SettingsGetResult"
    put:
      summary: Update settings
      operationId: updateSettings
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/SettingsUpdateBody"
      responses:
        "200":
          description: Settings updated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SettingsUpdateResult"
components:
  schemas:
    SettingsFindResult:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: "#/components/schemas/Settings"
        meta:
          type: object
    SettingsGetResult:
      type: object
      properties:
        data:
          $ref: "#/components/schemas/Settings"
    SettingsUpdateBody:
      type: object
      properties:
        key:
          type: string
        value:
          oneOf:
            - type: string
            - type: number
            - type: boolean
            - type: object
        category:
          type: string
        description:
          type: string
        calculate_target_for_non_working_days:
          type: boolean
          default: false
          description: "When true, system-created absent days that fall on a scheduled day off of the rep's assigned shift still trigger target calculation."
        end_of_day:
          type: string
          description: "Per-namespace day-cutover time as HH:mm. Propagated to company-namespaces.end_of_day."
        time_zone:
          type: string
          description: "Per-namespace IANA time zone. Propagated to company-namespaces.time_zone."
        end_of_day_mode:
          type: string
          enum: [fixed_time, shift_based]
          default: fixed_time
          description: "How the namespace determines the end-of-day cutover: fixed_time uses the company end_of_day setting; shift_based derives it from assigned day shifts."
        automatic_end_day_minutes_after_shift_end:
          type: integer
          minimum: 0
          maximum: 240
          default: 0
          description: "Shift-based mode only: minutes after a shift-based day's shift end before the system auto-closes it."
        start_day_outside_active_zone_action:
          type: string
          enum: [monitor, warning, block]
          default: warning
          description: "Action when a rep starts their day outside their active geo zone: `monitor` (allow and record silently), `warning` (allow but warn), or `block` (prevent)."
        start_visit_outside_active_zone_action:
          type: string
          enum: [monitor, warning, block]
          default: warning
          description: "Action when a rep starts a visit outside their active geo zone (same `monitor`/`warning`/`block` semantics as `start_day_outside_active_zone_action`)."
        work_outside_active_zone_action:
          type: string
          enum: [monitor, warning, block]
          default: warning
          description: "Action when a rep performs work outside their active geo zone (same `monitor`/`warning`/`block` semantics as `start_day_outside_active_zone_action`)."
        no_active_zone_action:
          type: string
          enum: [allow, block]
          default: allow
          description: "Behavior when a rep has no active geo zone: `allow` (work unrestricted) or `block` (prevent working)."
        use_accuracy_radius_near_zone_boundary:
          type: boolean
          default: true
          description: "When true, the device GPS accuracy radius is considered near a zone boundary — a position whose accuracy circle overlaps the zone counts as inside it."
        zone_boundary_grace_minutes:
          type: integer
          minimum: 0
          maximum: 60
          default: 5
          description: "Grace period in minutes around zone-boundary transitions before the configured outside-zone action is enforced (integer 0-60)."
    SettingsUpdateResult:
      type: object
      properties:
        data:
          $ref: "#/components/schemas/Settings"
    Settings:
      type: object
      properties:
        _id:
          type: string
        key:
          type: string
        value:
          oneOf:
            - type: string
            - type: number
            - type: boolean
            - type: object
        category:
          type: string
        description:
          type: string
        calculate_target_for_non_working_days:
          type: boolean
          default: false
          description: "When true, system-created absent days that fall on a scheduled day off of the rep's assigned shift still trigger target calculation."
        end_of_day_mode:
          type: string
          enum: [fixed_time, shift_based]
          default: fixed_time
          description: "How the namespace determines the end-of-day cutover: fixed_time uses the company end_of_day setting; shift_based derives it from assigned day shifts."
        automatic_end_day_minutes_after_shift_end:
          type: integer
          minimum: 0
          maximum: 240
          default: 0
          description: "Shift-based mode only: minutes after a shift-based day's shift end before the system auto-closes it."
        start_day_outside_active_zone_action:
          type: string
          enum: [monitor, warning, block]
          default: warning
          description: "Action when a rep starts their day outside their active geo zone: `monitor` (allow and record silently), `warning` (allow but warn), or `block` (prevent)."
        start_visit_outside_active_zone_action:
          type: string
          enum: [monitor, warning, block]
          default: warning
          description: "Action when a rep starts a visit outside their active geo zone (same `monitor`/`warning`/`block` semantics as `start_day_outside_active_zone_action`)."
        work_outside_active_zone_action:
          type: string
          enum: [monitor, warning, block]
          default: warning
          description: "Action when a rep performs work outside their active geo zone (same `monitor`/`warning`/`block` semantics as `start_day_outside_active_zone_action`)."
        no_active_zone_action:
          type: string
          enum: [allow, block]
          default: allow
          description: "Behavior when a rep has no active geo zone: `allow` (work unrestricted) or `block` (prevent working)."
        use_accuracy_radius_near_zone_boundary:
          type: boolean
          default: true
          description: "When true, the device GPS accuracy radius is considered near a zone boundary — a position whose accuracy circle overlaps the zone counts as inside it."
        zone_boundary_grace_minutes:
          type: integer
          minimum: 0
          maximum: 60
          default: 5
          description: "Grace period in minutes around zone-boundary transitions before the configured outside-zone action is enforced (integer 0-60)."
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
