{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://api.gofile.co.uk/schemas/v2/webhook-event.json",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "event_id",
    "event_version",
    "event_type",
    "occurred_at",
    "integration_id",
    "connection_id",
    "resource_id",
    "resource_type",
    "data"
  ],
  "properties": {
    "event_id": {
      "type": "string"
    },
    "event_version": {
      "const": "2"
    },
    "event_type": {
      "enum": [
        "connection.authorised",
        "connection.disconnected",
        "connection.reauthorisation_required",
        "vat.status.updated",
        "vat.filing.awaiting_approval",
        "vat.filing.requires_review",
        "vat.filing.submitted",
        "vat.filing.failed",
        "itsa.status.updated",
        "itsa.quarterly_update.submitted",
        "itsa.client_action.completed"
      ]
    },
    "occurred_at": {
      "type": "string",
      "format": "date-time"
    },
    "integration_id": {
      "type": "string"
    },
    "connection_id": {
      "type": "string",
      "pattern": "^hmc_[a-f0-9]{24}$"
    },
    "resource_id": {
      "type": "string"
    },
    "resource_type": {
      "enum": [
        "hmrc_connection",
        "vat_status",
        "vat_filing_session",
        "itsa_status",
        "itsa_quarterly_update",
        "itsa_client_action"
      ]
    },
    "data": {
      "type": "object",
      "properties": {
        "connection_id": {
          "type": "string"
        },
        "vat_number": {
          "type": "string",
          "pattern": "^[0-9]{9}$"
        }
      },
      "required": [
        "connection_id"
      ]
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "event_type": {
            "const": "connection.authorised"
          }
        }
      },
      "then": {
        "properties": {
          "resource_type": {
            "const": "hmrc_connection"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "event_type": {
            "const": "connection.disconnected"
          }
        }
      },
      "then": {
        "properties": {
          "resource_type": {
            "const": "hmrc_connection"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "event_type": {
            "const": "connection.reauthorisation_required"
          }
        }
      },
      "then": {
        "properties": {
          "resource_type": {
            "const": "hmrc_connection"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "event_type": {
            "const": "vat.status.updated"
          }
        }
      },
      "then": {
        "properties": {
          "resource_type": {
            "const": "vat_status"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "event_type": {
            "const": "vat.filing.awaiting_approval"
          }
        }
      },
      "then": {
        "properties": {
          "resource_type": {
            "const": "vat_filing_session"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "event_type": {
            "const": "vat.filing.requires_review"
          }
        }
      },
      "then": {
        "properties": {
          "resource_type": {
            "const": "vat_filing_session"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "event_type": {
            "const": "vat.filing.submitted"
          }
        }
      },
      "then": {
        "properties": {
          "resource_type": {
            "const": "vat_filing_session"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "event_type": {
            "const": "vat.filing.failed"
          }
        }
      },
      "then": {
        "properties": {
          "resource_type": {
            "const": "vat_filing_session"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "event_type": {
            "const": "itsa.status.updated"
          }
        }
      },
      "then": {
        "properties": {
          "resource_type": {
            "const": "itsa_status"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "event_type": {
            "const": "itsa.quarterly_update.submitted"
          }
        }
      },
      "then": {
        "properties": {
          "resource_type": {
            "const": "itsa_quarterly_update"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "event_type": {
            "const": "itsa.client_action.completed"
          }
        }
      },
      "then": {
        "properties": {
          "resource_type": {
            "const": "itsa_client_action"
          }
        }
      }
    }
  ]
}
