{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "type": "object",
  "title": "Referral Import Line",
  "description": "Represents the schema for a single line of the referral import JSONL file",
  "properties": {
    "referrerUser": {
      "$schema": "http://json-schema.org/draft-06/schema#",
      "title": "User Identifier Schema",
      "description": "The unique identifiers used to distinguish a user.",
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "title": "User Id",
          "description": "This user's unique identifier"
        },
        "accountId": {
          "type": "string",
          "title": "Account Id",
          "description": "The unique identifier of the account this user belongs to"
        }
      },
      "required": [
        "id",
        "accountId"
      ],
      "additionalProperties": false
    },
    "referredUser": {
      "$schema": "http://json-schema.org/draft-06/schema#",
      "title": "User Identifier Schema",
      "description": "The unique identifiers used to distinguish a user.",
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "title": "User Id",
          "description": "This user's unique identifier"
        },
        "accountId": {
          "type": "string",
          "title": "Account Id",
          "description": "The unique identifier of the account this user belongs to"
        }
      },
      "required": [
        "id",
        "accountId"
      ],
      "additionalProperties": false
    },
    "programId": {
      "type": "string",
      "title": "Program Id"
    },
    "dateReferralStarted": {
      "type": "integer",
      "title": "Date Referral Started"
    },
    "dateConverted": {
      "type": "integer",
      "title": "Date Converted"
    },
    "rewards": {
      "$ref": "#/definitions/rewards"
    }
  },
  "required": [
    "programId",
    "referrerUser",
    "referredUser"
  ],
  "additionalProperties": false,
  "definitions": {
    "rewardUnit": {
      "type": "string",
      "title": "Unit",
      "description": "The unit of credit associated with this reward (i.e. months or usd)"
    },
    "rewardName": {
      "type": [
        "string",
        "null"
      ],
      "title": "Reward Name"
    },
    "rewardDateExpires": {
      "type": [
        "integer",
        "null"
      ],
      "title": "Reward Expiry Date",
      "description": "The date this reward will expire"
    },
    "rewardCancellable": {
      "type": [
        "boolean",
        "null"
      ],
      "title": "Cancellable",
      "description": "Whether this reward can be cancelled"
    },
    "rewardDateScheduledFor": {
      "type": [
        "integer",
        "null"
      ],
      "title": "Scheduled Reward Given Date",
      "description": "If the reward is created in a PENDING state this is the date we will attempt to 'give' it"
    },
    "integrationSettings": {
      "type": "object",
      "title": "Integration Settings",
      "properties": {
        "templateId": {
          "type": "string",
          "title": "Email Template ID"
        },
        "giftId": {
          "type": "string"
        },
        "utid": {
          "type": "string"
        }
      }
    },
    "rewards": {
      "type": "array",
      "title": "Rewards",
      "items": {
        "$schema": "http://json-schema.org/draft-06/schema#",
        "title": "Reward API Input",
        "description": "Defines the reward API data input structure.",
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "title": "Reward Type",
            "enum": [
              "PCT_DISCOUNT",
              "FUELTANK",
              "CREDIT",
              "INTEGRATION"
            ]
          }
        },
        "dependencies": {
          "type": {
            "oneOf": [
              {
                "properties": {
                  "type": {
                    "enum": [
                      "PCT_DISCOUNT"
                    ]
                  },
                  "discountPercent": {
                    "type": "integer",
                    "title": "Discount Percent",
                    "exclusiveMinimum": 0,
                    "maximum": 100,
                    "description": "The discount associated with this reward"
                  },
                  "name": {
                    "$ref": "#/definitions/rewardName"
                  },
                  "dateExpires": {
                    "$ref": "#/definitions/rewardDateExpires"
                  },
                  "cancellable": {
                    "$ref": "#/definitions/rewardCancellable"
                  },
                  "dateScheduledFor": {
                    "$ref": "#/definitions/rewardDateScheduledFor"
                  },
                  "programRewardKey": {
                    "type": "string",
                    "title": "Reward Key"
                  },
                  "dateGiven": {
                    "type": "integer",
                    "title": "Date Given"
                  },
                  "userId": {
                    "type": "string",
                    "title": "User Id"
                  },
                  "accountId": {
                    "type": "string",
                    "title": "Account Id"
                  }
                },
                "additionalProperties": false,
                "required": [
                  "type",
                  "discountPercent"
                ]
              },
              {
                "properties": {
                  "type": {
                    "enum": [
                      "FUELTANK"
                    ]
                  },
                  "fuelTankCode": {
                    "type": "string",
                    "title": "Fuel Tank Code",
                    "description": "The associated coupon code uploaded via the fuel tank API or portal code manager"
                  },
                  "unit": {
                    "$ref": "#/definitions/rewardUnit"
                  },
                  "amount": {
                    "type": "string",
                    "title": "Amount",
                    "description": "The amount of credit or discount to be given"
                  },
                  "dateExpires": {
                    "$ref": "#/definitions/rewardDateExpires"
                  },
                  "fuelTankType": {
                    "type": "string",
                    "title": "Fuel Tank Type",
                    "description": "The type of fuel tank reward being given",
                    "enum": [
                      "PCT_DISCOUNT",
                      "CREDIT"
                    ]
                  },
                  "cancellable": {
                    "$ref": "#/definitions/rewardCancellable"
                  },
                  "programRewardKey": {
                    "type": "string",
                    "title": "Reward Key"
                  },
                  "dateGiven": {
                    "type": "integer",
                    "title": "Date Given"
                  },
                  "userId": {
                    "type": "string",
                    "title": "User Id"
                  },
                  "accountId": {
                    "type": "string",
                    "title": "Account Id"
                  }
                },
                "additionalProperties": false,
                "required": [
                  "type",
                  "fuelTankCode",
                  "fuelTankType",
                  "amount"
                ]
              },
              {
                "properties": {
                  "type": {
                    "enum": [
                      "CREDIT"
                    ]
                  },
                  "unit": {
                    "$ref": "#/definitions/rewardUnit"
                  },
                  "name": {
                    "$ref": "#/definitions/rewardName"
                  },
                  "assignedCredit": {
                    "type": "integer",
                    "title": "Assigned Credit",
                    "exclusiveMinimum": 0,
                    "description": "The initial redeemable credit assigned to be assigned to reward"
                  },
                  "dateExpires": {
                    "$ref": "#/definitions/rewardDateExpires"
                  },
                  "cancellable": {
                    "$ref": "#/definitions/rewardCancellable"
                  },
                  "dateScheduledFor": {
                    "$ref": "#/definitions/rewardDateScheduledFor"
                  },
                  "redemptions": {
                    "$ref": "#/definitions/redemptions"
                  },
                  "programRewardKey": {
                    "type": "string",
                    "title": "Reward Key"
                  },
                  "dateGiven": {
                    "type": "integer",
                    "title": "Date Given"
                  },
                  "userId": {
                    "type": "string",
                    "title": "User Id"
                  },
                  "accountId": {
                    "type": "string",
                    "title": "Account Id"
                  }
                },
                "additionalProperties": false,
                "required": [
                  "type",
                  "unit",
                  "assignedCredit"
                ]
              },
              {
                "properties": {
                  "type": {
                    "enum": [
                      "INTEGRATION"
                    ]
                  },
                  "unit": {
                    "$ref": "#/definitions/rewardUnit"
                  },
                  "name": {
                    "$ref": "#/definitions/rewardName"
                  },
                  "description": {
                    "type": "string",
                    "title": "Reward Description",
                    "description": "This text describes the integration reward given in more detail"
                  },
                  "valueInCents": {
                    "type": "string",
                    "title": "Reward Amount",
                    "description": "The value in base currency unit (i.e. cents) to be assigned to this reward"
                  },
                  "integrationSettings": {
                    "$ref": "#/definitions/integrationSettings"
                  },
                  "programRewardKey": {
                    "type": "string",
                    "title": "Reward Key"
                  },
                  "dateGiven": {
                    "type": "integer",
                    "title": "Date Given"
                  },
                  "userId": {
                    "type": "string",
                    "title": "User Id"
                  },
                  "accountId": {
                    "type": "string",
                    "title": "Account Id"
                  }
                },
                "additionalProperties": false,
                "required": [
                  "type",
                  "unit",
                  "valueInCents",
                  "integrationSettings"
                ]
              }
            ]
          }
        },
        "definitions": {
          "rewardUnit": {
            "type": "string",
            "title": "Unit",
            "description": "The unit of credit associated with this reward (i.e. months or usd)"
          },
          "rewardName": {
            "type": [
              "string",
              "null"
            ],
            "title": "Reward Name"
          },
          "rewardDateExpires": {
            "type": [
              "integer",
              "null"
            ],
            "title": "Reward Expiry Date",
            "description": "The date this reward will expire"
          },
          "rewardCancellable": {
            "type": [
              "boolean",
              "null"
            ],
            "title": "Cancellable",
            "description": "Whether this reward can be cancelled"
          },
          "rewardDateScheduledFor": {
            "type": [
              "integer",
              "null"
            ],
            "title": "Scheduled Reward Given Date",
            "description": "If the reward is created in a PENDING state this is the date we will attempt to 'give' it"
          },
          "integrationSettings": {
            "type": "object",
            "title": "Integration Settings",
            "properties": {
              "templateId": {
                "type": "string",
                "title": "Email Template ID"
              },
              "giftId": {
                "type": "string"
              },
              "utid": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "redemptions": {
      "type": "array",
      "title": "Redemptions",
      "items": {
        "type": "object",
        "properties": {
          "quantityRedeemed": {
            "type": "integer",
            "title": "Redeemed Amount"
          },
          "dateRedeemed": {
            "type": "integer",
            "title": "Date Redeemed"
          }
        },
        "required": [
          "quantityRedeemed"
        ],
        "additionalProperties": false
      }
    }
  }
}