{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/affiliaterail-com/json-schema/affiliaterail-com-rule-revision-list-schema.json",
  "title": "RuleRevisionList",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/affiliaterail-com-commission-rules-api-openapi.yml#/components/schemas/RuleRevisionList",
  "type": "object",
  "properties": {
    "data": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/RuleRevision"
      }
    },
    "has_more": {
      "type": "boolean",
      "description": "Pass the last object's id as `starting_after` to fetch the next page"
    },
    "total_count": {
      "type": "integer",
      "description": "Count of every object matching the filters, ignoring the cursor"
    }
  },
  "required": [
    "data",
    "has_more",
    "total_count"
  ],
  "$defs": {
    "Condition": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "field": {
              "type": "string"
            },
            "op": {
              "type": "string",
              "enum": [
                "eq",
                "neq",
                "gt",
                "gte",
                "lt",
                "lte",
                "between",
                "in",
                "not_in",
                "contains",
                "starts_with",
                "is_true",
                "is_false"
              ]
            },
            "value": {}
          },
          "required": [
            "field",
            "op"
          ]
        },
        {
          "type": "object",
          "properties": {
            "all": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/Condition"
              }
            }
          },
          "required": [
            "all"
          ]
        },
        {
          "type": "object",
          "properties": {
            "any": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/Condition"
              }
            }
          },
          "required": [
            "any"
          ]
        },
        {
          "type": "object",
          "properties": {
            "not": {
              "$ref": "#/$defs/Condition"
            }
          },
          "required": [
            "not"
          ]
        }
      ],
      "description": "A comparison `{ field, op, value }` or a group `{ all: [...] }`, `{ any: [...] }`, `{ not: ... }`. Numeric ranges are inclusive."
    },
    "RuleRevision": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^(sample_)?flr_",
          "description": "Prefixed id (`flr_…`)"
        },
        "object": {
          "type": "string",
          "enum": [
            "rule_revision"
          ]
        },
        "rule_id": {
          "type": "string",
          "pattern": "^(sample_)?flw_",
          "description": "Prefixed id (`flw_…`)"
        },
        "program_id": {
          "type": "string",
          "pattern": "^(sample_)?prg_",
          "description": "Prefixed id (`prg_…`)"
        },
        "snapshot": {
          "$ref": "#/$defs/RuleSnapshot"
        },
        "changed_by": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^(sample_)?usr_",
          "description": "The signed-in merchant who saved the edit, or null when it came from the API, an import or a job"
        },
        "created_at": {
          "type": "string",
          "format": "date-time",
          "description": "When this version stopped being true, which is when the edit that replaced it was saved"
        }
      },
      "required": [
        "id",
        "object",
        "rule_id",
        "program_id",
        "snapshot",
        "changed_by",
        "created_at"
      ]
    },
    "RuleSnapshot": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^(sample_)?flw_",
          "description": "Prefixed id (`flw_…`)"
        },
        "name": {
          "type": "string"
        },
        "group_id": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^(sample_)?grp_",
          "description": "Prefixed id (`grp_…`)"
        },
        "partner_id": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^(sample_)?part_",
          "description": "Prefixed id (`part_…`)"
        },
        "trigger": {
          "type": "string",
          "enum": [
            "new_payment",
            "new_signup"
          ]
        },
        "action": {
          "type": "string",
          "enum": [
            "generate_commission",
            "switch_group"
          ]
        },
        "rate_type": {
          "type": "string",
          "enum": [
            "percent",
            "fixed"
          ]
        },
        "rate_value": {
          "type": "integer",
          "description": "Basis points for percent, minor units for fixed. The fallback when no branch matches."
        },
        "approval_mode": {
          "type": "string",
          "enum": [
            "immediate",
            "after_days",
            "manual"
          ]
        },
        "approval_delay_days": {
          "type": [
            "integer",
            "null"
          ]
        },
        "priority": {
          "type": "integer",
          "description": "Lower runs first"
        },
        "status": {
          "type": "string",
          "enum": [
            "active",
            "inactive"
          ]
        },
        "branches": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^(sample_)?flb_",
                "description": "Prefixed id (`flb_…`)"
              },
              "position": {
                "type": "integer"
              },
              "label": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "conditions": {
                "$ref": "#/$defs/Condition"
              },
              "rate_type": {
                "type": "string",
                "enum": [
                  "percent",
                  "fixed"
                ]
              },
              "rate_value": {
                "type": "integer"
              }
            },
            "required": [
              "id",
              "position",
              "label",
              "conditions",
              "rate_type",
              "rate_value"
            ]
          }
        }
      },
      "required": [
        "id",
        "name",
        "group_id",
        "partner_id",
        "trigger",
        "action",
        "rate_type",
        "rate_value",
        "approval_mode",
        "approval_delay_days",
        "priority",
        "status",
        "branches"
      ],
      "description": "The rule as it was BEFORE this edit"
    }
  }
}