{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://standards.msadsnetwork.com/downloads/schemas/payout-statement.schema.json",
  "title": "payout.json statement v0.1 (public draft)",
  "type": "object",
  "required": [
    "ver",
    "statement_id",
    "issuer",
    "payee",
    "period",
    "currency",
    "gross",
    "deductions",
    "fees",
    "net",
    "payment",
    "issued_at"
  ],
  "additionalProperties": false,
  "properties": {
    "ver": {
      "const": "0.1"
    },
    "statement_id": {
      "type": "string",
      "minLength": 4,
      "maxLength": 64
    },
    "issuer": {
      "type": "object",
      "required": [
        "name",
        "domain",
        "sellers_json"
      ],
      "properties": {
        "name": {
          "type": "string"
        },
        "domain": {
          "type": "string"
        },
        "sellers_json": {
          "type": "string",
          "pattern": "^https://"
        }
      },
      "additionalProperties": false
    },
    "payee": {
      "type": "object",
      "required": [
        "seller_id"
      ],
      "properties": {
        "seller_id": {
          "type": "string",
          "minLength": 1
        },
        "name": {
          "type": "string"
        },
        "domain": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "period": {
      "type": "object",
      "required": [
        "from",
        "to"
      ],
      "properties": {
        "from": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
        },
        "to": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
        }
      },
      "additionalProperties": false
    },
    "currency": {
      "type": "string",
      "pattern": "^[A-Z]{3}$"
    },
    "gross": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,6})?$"
    },
    "lines": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "product",
          "event",
          "count",
          "amount"
        ],
        "properties": {
          "product": {
            "type": "string"
          },
          "event": {
            "enum": [
              "impression",
              "click",
              "conversion",
              "task"
            ]
          },
          "count": {
            "type": "integer",
            "minimum": 0
          },
          "amount": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d{1,6})?$"
          }
        },
        "additionalProperties": false
      }
    },
    "deductions": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "ver",
          "code",
          "event",
          "count",
          "amount",
          "currency",
          "period",
          "detected_by",
          "appeal",
          "reversible"
        ],
        "additionalProperties": false,
        "properties": {
          "ver": {
            "const": "0.1"
          },
          "code": {
            "anyOf": [
              {
                "enum": [
                  "IVT-G-DC",
                  "IVT-G-BOT",
                  "IVT-G-PREFETCH",
                  "IVT-G-DUP",
                  "IVT-G-INVALIDUA",
                  "IVT-S-TOKEN",
                  "IVT-S-RATE",
                  "IVT-S-PROXY",
                  "IVT-S-EMU",
                  "IVT-S-INJECT",
                  "IVT-S-CLICKSPAM",
                  "IVT-S-SDKSPOOF",
                  "IVT-P-PROBATION",
                  "IVT-P-POLICY",
                  "IVT-P-CLIENT"
                ]
              },
              {
                "type": "string",
                "pattern": "^IVT-X-[A-Za-z0-9]+-[A-Z0-9-]+$"
              }
            ]
          },
          "event": {
            "enum": [
              "impression",
              "click",
              "conversion",
              "task"
            ]
          },
          "count": {
            "type": "integer",
            "minimum": 0
          },
          "amount": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d{1,6})?$"
          },
          "currency": {
            "type": "string",
            "pattern": "^[A-Z]{3}$"
          },
          "period": {
            "type": "object",
            "required": [
              "from",
              "to"
            ],
            "properties": {
              "from": {
                "type": "string",
                "format": "date",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
              },
              "to": {
                "type": "string",
                "format": "date",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
              }
            },
            "additionalProperties": false
          },
          "detected_by": {
            "type": "string",
            "minLength": 2
          },
          "evidence_url": {
            "type": "string",
            "pattern": "^https://"
          },
          "appeal": {
            "type": "object",
            "required": [
              "deadline"
            ],
            "anyOf": [
              {
                "required": [
                  "url"
                ]
              },
              {
                "required": [
                  "email"
                ]
              }
            ],
            "properties": {
              "url": {
                "type": "string",
                "pattern": "^https://"
              },
              "email": {
                "type": "string",
                "format": "email",
                "pattern": "@"
              },
              "deadline": {
                "type": "string",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
              }
            },
            "additionalProperties": false
          },
          "reversible": {
            "type": "boolean"
          }
        }
      }
    },
    "fees": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "type",
          "amount"
        ],
        "properties": {
          "type": {
            "enum": [
              "platform",
              "payment",
              "fx",
              "tax_withholding"
            ]
          },
          "amount": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d{1,6})?$"
          },
          "note": {
            "type": "string",
            "maxLength": 200
          }
        },
        "additionalProperties": false
      }
    },
    "adjustments": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "reason",
          "amount"
        ],
        "properties": {
          "reason": {
            "type": "string"
          },
          "amount": {
            "type": "string",
            "pattern": "^-?\\d+(\\.\\d{1,6})?$"
          }
        },
        "additionalProperties": false
      }
    },
    "net": {
      "type": "string",
      "pattern": "^-?\\d+(\\.\\d{1,6})?$"
    },
    "payment": {
      "type": "object",
      "required": [
        "status"
      ],
      "properties": {
        "status": {
          "enum": [
            "scheduled",
            "paid",
            "held",
            "below_threshold"
          ]
        },
        "date": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
        },
        "method": {
          "enum": [
            "bank_transfer",
            "wallet",
            "paypal",
            "payoneer",
            "crypto"
          ]
        },
        "reference": {
          "type": "string",
          "maxLength": 40
        },
        "threshold": {
          "type": "string",
          "pattern": "^\\d+(\\.\\d{1,6})?$"
        }
      },
      "additionalProperties": false
    },
    "issued_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T"
    },
    "signature": {
      "type": "string"
    }
  }
}