openapi: 3.0.3
info:
  title: Repzo API - Target Rule
  version: 1.0.0
  description: OpenAPI specification for Repzo Target Rule (Rule) endpoints.
servers:
  - url: https://sv.api.repzo.me
paths:
  /target-rule:
    get:
      summary: Find target rules
      operationId: findTargetRules
      parameters:
        - in: query
          name: params
          schema:
            type: object
          description: Query parameters for filtering target rules
      responses:
        "200":
          description: A list of target rules
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TargetRuleFindResult"
    post:
      summary: Create a target rule
      operationId: createTargetRule
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/TargetRuleCreateBody"
      responses:
        "201":
          description: Target rule created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TargetRuleCreateResult"
  /target-rule/{id}:
    get:
      summary: Get a target rule by ID
      operationId: getTargetRule
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Target rule details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TargetRuleGetResult"
    put:
      summary: Update a target rule
      operationId: updateTargetRule
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/TargetRuleUpdateBody"
      responses:
        "200":
          description: Target rule updated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TargetRuleUpdateResult"
    delete:
      summary: Disable a target rule
      operationId: removeTargetRule
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Target rule disabled
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TargetRuleRemoveResult"
components:
  schemas:
    TargetRuleType:
      type: string
      enum:
        - rep-visit
        - time-clock
        - rep-photo
        - rep-invoice
        - rep-proforma
        - item-status
        - rep-payment
    TargetRulePeriod:
      type: string
      enum:
        - daily
        - weekly
        - monthly
        - quarterly
        - yearly
    TargetRulePoint:
      type: object
      properties:
        ratio:
          type: number
        points:
          type: number
    TargetRuleFilterEntry:
      type: object
      properties:
        filter:
          type: string
        value:
          type: array
          items: {}
        photoCount:
          type: number
    TargetRuleDetails:
      type: object
      properties:
        type:
          $ref: "#/components/schemas/TargetRuleType"
        filter:
          type: array
          items:
            $ref: "#/components/schemas/TargetRuleFilterEntry"
        limit:
          type: number
        aggregation_key:
          type: string
        period:
          $ref: "#/components/schemas/TargetRulePeriod"
        required_target:
          type: object
          properties:
            type:
              type: string
              enum: [absolute, assigned_to]
            value:
              type: number
    TargetRuleFindResult:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: "#/components/schemas/TargetRule"
        meta:
          type: object
    TargetRuleCreateBody:
      type: object
      required:
        - name
        - type
        - details
      properties:
        name:
          type: string
        type:
          $ref: "#/components/schemas/TargetRuleType"
        details:
          $ref: "#/components/schemas/TargetRuleDetails"
        points:
          type: array
          items:
            $ref: "#/components/schemas/TargetRulePoint"
        allowOverOne:
          type: boolean
        targets_group:
          type: string
        disabled:
          type: boolean
    TargetRuleCreateResult:
      type: object
      properties:
        data:
          $ref: "#/components/schemas/TargetRule"
    TargetRuleGetResult:
      type: object
      properties:
        data:
          $ref: "#/components/schemas/TargetRule"
    TargetRuleUpdateBody:
      type: object
      properties:
        name:
          type: string
        details:
          $ref: "#/components/schemas/TargetRuleDetails"
        points:
          type: array
          items:
            $ref: "#/components/schemas/TargetRulePoint"
        allowOverOne:
          type: boolean
        targets_group:
          type: string
        disabled:
          type: boolean
    TargetRuleUpdateResult:
      type: object
      properties:
        data:
          $ref: "#/components/schemas/TargetRule"
    TargetRuleRemoveResult:
      type: object
      properties:
        data:
          $ref: "#/components/schemas/TargetRule"
    TargetRule:
      type: object
      properties:
        _id:
          type: string
        name:
          type: string
        type:
          $ref: "#/components/schemas/TargetRuleType"
        points:
          type: array
          items:
            $ref: "#/components/schemas/TargetRulePoint"
        allowOverOne:
          type: boolean
        targets_group:
          type: string
        details:
          $ref: "#/components/schemas/TargetRuleDetails"
        disabled:
          type: boolean
        company_namespace:
          type: array
          items:
            type: string
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
