{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/voltplan-app/json-schema/voltplan-app-admin-affiliate-impact-dashboard-schema.json",
  "title": "AdminAffiliateImpactDashboard",
  "x-generated": "2026-11-28",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/voltplan-app-openapi.json#/components/schemas/AdminAffiliateImpactDashboard",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "generatedAt",
    "range",
    "currency",
    "totals",
    "daily",
    "countries",
    "products",
    "sources",
    "actions"
  ],
  "properties": {
    "generatedAt": {
      "type": "integer",
      "description": "Unix epoch milliseconds."
    },
    "range": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "days",
        "start",
        "end"
      ],
      "properties": {
        "days": {
          "type": "integer",
          "enum": [
            7,
            30,
            90
          ]
        },
        "start": {
          "type": "string",
          "format": "date"
        },
        "end": {
          "type": "string",
          "format": "date",
          "description": "Today (UTC)."
        }
      }
    },
    "currency": {
      "type": [
        "string",
        "null"
      ]
    },
    "totals": {
      "$ref": "#/$defs/AdminAffiliateImpactTotals"
    },
    "daily": {
      "type": "array",
      "description": "One entry per day of the window, oldest first.",
      "items": {
        "$ref": "#/$defs/AdminAffiliateImpactDay"
      }
    },
    "countries": {
      "type": "array",
      "description": "Most Impact clicks first; countries without clicks or purchases are left out.",
      "items": {
        "$ref": "#/$defs/AdminAffiliateImpactCountry"
      }
    },
    "products": {
      "type": "array",
      "description": "Most commission first, then most of our clicks.",
      "items": {
        "$ref": "#/$defs/AdminAffiliateImpactProduct"
      }
    },
    "sources": {
      "type": "array",
      "description": "Most clicks first.",
      "items": {
        "$ref": "#/$defs/AdminAffiliateImpactSource"
      }
    },
    "actions": {
      "type": "array",
      "description": "Every purchase in the window, newest first, reversed ones included.",
      "items": {
        "$ref": "#/$defs/AdminAffiliateImpactAction"
      }
    }
  },
  "$defs": {
    "AdminAffiliateImpactAction": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "eventDate",
        "state",
        "amount",
        "payout",
        "currency",
        "country",
        "componentId",
        "componentName",
        "subId1",
        "subId3",
        "promoCode"
      ],
      "properties": {
        "id": {
          "type": "string",
          "description": "Impact action id."
        },
        "eventDate": {
          "type": "string",
          "description": "Purchase time as Impact sends it (ISO 8601)."
        },
        "state": {
          "type": "string",
          "enum": [
            "PENDING",
            "APPROVED",
            "REVERSED"
          ]
        },
        "amount": {
          "type": "number",
          "description": "Order value."
        },
        "payout": {
          "type": "number",
          "description": "Commission."
        },
        "currency": {
          "type": [
            "string",
            "null"
          ]
        },
        "country": {
          "type": [
            "string",
            "null"
          ],
          "description": "Customer country, upper case."
        },
        "componentId": {
          "type": [
            "string",
            "null"
          ],
          "description": "`SubId2` of the winning click."
        },
        "componentName": {
          "type": [
            "string",
            "null"
          ]
        },
        "subId1": {
          "type": [
            "string",
            "null"
          ]
        },
        "subId3": {
          "type": [
            "string",
            "null"
          ]
        },
        "promoCode": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "AdminAffiliateImpactCountry": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "country",
        "clicks",
        "actions",
        "payout",
        "delivers"
      ],
      "properties": {
        "country": {
          "type": "string",
          "description": "ISO code in upper case, or `UNKNOWN` for purchases without one."
        },
        "clicks": {
          "type": "integer",
          "minimum": 0
        },
        "actions": {
          "type": "integer",
          "minimum": 0
        },
        "payout": {
          "type": "number"
        },
        "delivers": {
          "type": "boolean",
          "description": "A Renogy shop delivers to this country (`src/lib/renogyShipping.ts`)."
        }
      }
    },
    "AdminAffiliateImpactDay": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "date",
        "clicks",
        "actions",
        "payout"
      ],
      "properties": {
        "date": {
          "type": "string",
          "format": "date"
        },
        "clicks": {
          "type": "integer",
          "minimum": 0
        },
        "actions": {
          "type": "integer",
          "minimum": 0
        },
        "payout": {
          "type": "number"
        }
      }
    },
    "AdminAffiliateImpactProduct": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "componentId",
        "name",
        "ourClicks",
        "actions",
        "saleAmount",
        "payout"
      ],
      "properties": {
        "componentId": {
          "type": "string",
          "description": "Id of the `components` record (`SubId2`)."
        },
        "name": {
          "type": "string",
          "description": "Component name, or the id when unknown."
        },
        "ourClicks": {
          "type": "integer",
          "minimum": 0
        },
        "actions": {
          "type": "integer",
          "minimum": 0
        },
        "saleAmount": {
          "type": "number"
        },
        "payout": {
          "type": "number"
        }
      }
    },
    "AdminAffiliateImpactSource": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source",
        "clicks"
      ],
      "properties": {
        "source": {
          "type": "string",
          "description": "Click `source` without the `_affiliate` / `_amazon_search` suffix."
        },
        "clicks": {
          "type": "integer",
          "minimum": 1
        }
      }
    },
    "AdminAffiliateImpactTotals": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "clicks",
        "deliveryClicks",
        "actions",
        "saleAmount",
        "payout",
        "pendingPayout",
        "approvedPayout",
        "reversedPayout",
        "epc",
        "conversionRate",
        "ourClicks",
        "ourDeliveryClicks",
        "ourClicksWithoutCountry"
      ],
      "properties": {
        "clicks": {
          "type": "integer",
          "minimum": 0,
          "description": "Impact clicks (sum of `daily[].clicks`)."
        },
        "deliveryClicks": {
          "type": "integer",
          "minimum": 0,
          "description": "Impact clicks from countries a Renogy shop delivers to (sum of `countries[].clicks` where `delivers`)."
        },
        "actions": {
          "type": "integer",
          "minimum": 0,
          "description": "Purchases that are not reversed."
        },
        "saleAmount": {
          "type": "number",
          "description": "Order value of those purchases."
        },
        "payout": {
          "type": "number",
          "description": "Commission of pending and approved purchases."
        },
        "pendingPayout": {
          "type": "number"
        },
        "approvedPayout": {
          "type": "number"
        },
        "reversedPayout": {
          "type": "number"
        },
        "epc": {
          "type": "number",
          "description": "`payout / clicks`, 0 without clicks."
        },
        "conversionRate": {
          "type": "number",
          "description": "`actions / clicks`, 0 without clicks."
        },
        "ourClicks": {
          "type": "integer",
          "minimum": 0,
          "description": "Our redirects to `renogy.sjv.io` in the window, bots removed."
        },
        "ourDeliveryClicks": {
          "type": "integer",
          "minimum": 0,
          "description": "Of `ourClicks`, those whose recorded `visitor_country` is a Renogy delivery country."
        },
        "ourClicksWithoutCountry": {
          "type": "integer",
          "minimum": 0,
          "description": "Of `ourClicks`, those without a recorded `visitor_country` (every row before 2026-11-16)."
        }
      }
    }
  }
}