{
  "$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"
            }
          },
          "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"
            }
          },
          "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"
            }
          },
          "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"
            }
          },
          "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"
        }
      }
    }
  }
}