{
  "$defs": {
    "PeriodDeduction": {
      "additionalProperties": false,
      "properties": {
        "name": {
          "maxLength": 100,
          "minLength": 1,
          "title": "Name",
          "type": "string"
        },
        "amount": {
          "anyOf": [
            {
              "minimum": 0.0,
              "type": "number"
            },
            {
              "pattern": "^(?!^[-+.]*$)[+-]?0*(?:\\d{0,16}|(?=[\\d.]{1,19}0*$)\\d{0,16}\\.\\d{0,2}0*$)",
              "type": "string"
            }
          ],
          "title": "Amount"
        },
        "evidence_ref": {
          "maxLength": 300,
          "minLength": 1,
          "title": "Evidence Ref",
          "type": "string"
        },
        "treatment": {
          "const": "additional_to_source_reported_basis",
          "default": "additional_to_source_reported_basis",
          "title": "Treatment",
          "type": "string"
        }
      },
      "required": [
        "name",
        "amount",
        "evidence_ref"
      ],
      "title": "PeriodDeduction",
      "type": "object"
    }
  },
  "additionalProperties": false,
  "properties": {
    "agreement_id": {
      "maxLength": 100,
      "minLength": 1,
      "title": "Agreement Id",
      "type": "string"
    },
    "tenant_id": {
      "title": "Tenant Id",
      "type": "string"
    },
    "version": {
      "default": "1.0",
      "title": "Version",
      "type": "string"
    },
    "model": {
      "enum": [
        "cpa",
        "cpl",
        "revshare",
        "hybrid"
      ],
      "title": "Model",
      "type": "string"
    },
    "operator_id": {
      "title": "Operator Id",
      "type": "string"
    },
    "partner_ids": {
      "items": {
        "type": "string"
      },
      "title": "Partner Ids",
      "type": "array"
    },
    "geos": {
      "items": {
        "type": "string"
      },
      "title": "Geos",
      "type": "array"
    },
    "currency": {
      "enum": [
        "EUR",
        "USD",
        "GBP",
        "CAD",
        "AUD",
        "CHF",
        "SEK",
        "NOK",
        "DKK",
        "BRL",
        "MXN",
        "PLN",
        "CZK",
        "ZAR",
        "INR"
      ],
      "title": "Currency",
      "type": "string"
    },
    "effective_from": {
      "format": "date-time",
      "title": "Effective From",
      "type": "string"
    },
    "effective_to": {
      "format": "date-time",
      "title": "Effective To",
      "type": "string"
    },
    "settlement_due_at": {
      "anyOf": [
        {
          "format": "date-time",
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Settlement Due At"
    },
    "settlement_basis": {
      "const": "agreement_pool",
      "default": "agreement_pool",
      "title": "Settlement Basis",
      "type": "string"
    },
    "cpa_rate": {
      "anyOf": [
        {
          "minimum": 0.0,
          "type": "number"
        },
        {
          "pattern": "^(?!^[-+.]*$)[+-]?0*(?:\\d{0,10}|(?=[\\d.]{1,13}0*$)\\d{0,10}\\.\\d{0,2}0*$)",
          "type": "string"
        }
      ],
      "default": "0",
      "title": "Cpa Rate"
    },
    "revshare_rate": {
      "anyOf": [
        {
          "maximum": 1.0,
          "minimum": 0.0,
          "type": "number"
        },
        {
          "pattern": "^(?!^[-+.]*$)[+-]?0*(?:\\d{0,2}|(?=[\\d.]{1,9}0*$)\\d{0,2}\\.\\d{0,6}0*$)",
          "type": "string"
        }
      ],
      "default": "0",
      "title": "Revshare Rate"
    },
    "minimum_deposit": {
      "anyOf": [
        {
          "minimum": 0.0,
          "type": "number"
        },
        {
          "pattern": "^(?!^[-+.]*$)[+-]?0*(?:\\d{0,10}|(?=[\\d.]{1,13}0*$)\\d{0,10}\\.\\d{0,2}0*$)",
          "type": "string"
        }
      ],
      "default": "20",
      "title": "Minimum Deposit"
    },
    "qualification_days": {
      "default": 30,
      "maximum": 365,
      "minimum": 1,
      "title": "Qualification Days",
      "type": "integer"
    },
    "kyc_required": {
      "default": true,
      "title": "Kyc Required",
      "type": "boolean"
    },
    "negative_carryover": {
      "default": false,
      "title": "Negative Carryover",
      "type": "boolean"
    },
    "opening_carryover": {
      "anyOf": [
        {
          "maximum": 0.0,
          "type": "number"
        },
        {
          "pattern": "^(?!^[-+.]*$)[+-]?0*(?:\\d{0,16}|(?=[\\d.]{1,19}0*$)\\d{0,16}\\.\\d{0,2}0*$)",
          "type": "string"
        }
      ],
      "default": "0",
      "title": "Opening Carryover"
    },
    "ngr_basis": {
      "default": "Source-reported NGR; deductions must match the configured agreement",
      "title": "Ngr Basis",
      "type": "string"
    },
    "reference_source": {
      "default": "backend",
      "title": "Reference Source",
      "type": "string"
    },
    "acquisition_source": {
      "default": "tracker",
      "title": "Acquisition Source",
      "type": "string"
    },
    "settlement_source": {
      "default": "finance",
      "title": "Settlement Source",
      "type": "string"
    },
    "callback_source": {
      "default": "partner_platform",
      "title": "Callback Source",
      "type": "string"
    },
    "callback_grace_minutes": {
      "default": 120,
      "maximum": 10080,
      "minimum": 1,
      "title": "Callback Grace Minutes",
      "type": "integer"
    },
    "conversion_event_type": {
      "default": "ftd",
      "enum": [
        "ftd",
        "qualified_lead",
        "sale",
        "funded_account"
      ],
      "title": "Conversion Event Type",
      "type": "string"
    },
    "callback_event_type": {
      "default": "partner_ftd",
      "enum": [
        "partner_ftd",
        "partner_conversion"
      ],
      "title": "Callback Event Type",
      "type": "string"
    },
    "revenue_event_type": {
      "default": "ngr",
      "enum": [
        "ngr",
        "revenue"
      ],
      "title": "Revenue Event Type",
      "type": "string"
    },
    "deposit_required": {
      "default": true,
      "title": "Deposit Required",
      "type": "boolean"
    },
    "period_deductions": {
      "default": [],
      "items": {
        "$ref": "#/$defs/PeriodDeduction"
      },
      "maxItems": 30,
      "title": "Period Deductions",
      "type": "array"
    },
    "settlement_cap": {
      "anyOf": [
        {
          "minimum": 0.0,
          "type": "number"
        },
        {
          "pattern": "^(?!^[-+.]*$)[+-]?0*(?:\\d{0,16}|(?=[\\d.]{1,19}0*$)\\d{0,16}\\.\\d{0,2}0*$)",
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Settlement Cap"
    },
    "settlement_cadence": {
      "const": "explicit_period",
      "default": "explicit_period",
      "title": "Settlement Cadence",
      "type": "string"
    },
    "terms_evidence_ref": {
      "anyOf": [
        {
          "maxLength": 300,
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Terms Evidence Ref"
    },
    "notes": {
      "default": "",
      "maxLength": 3000,
      "title": "Notes",
      "type": "string"
    }
  },
  "required": [
    "agreement_id",
    "tenant_id",
    "model",
    "operator_id",
    "partner_ids",
    "geos",
    "currency",
    "effective_from",
    "effective_to"
  ],
  "title": "Agreement",
  "type": "object"
}
