{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://department-for-transport-streetmanager.github.io/street-manager-docs/api-documentation/json/event-notifier-message.json",
  "title": "Event Notifier Message",
  "description": "A notification message a subscriber will receive when subscribed to a topic",
  "type": "object",
  "definitions": {
    "object_data": {
      "description": "The data of the object reference",
      "type": "object",
      "required": [
        "usrn",
        "street_name",
        "area_name",
        "town",
        "highway_authority",
        "highway_authority_swa_code"
      ],
      "properties": {
        "work_reference_number": {
          "description": "Reference number unique to a Work",
          "type": "string"
        },
        "permit_reference_number": {
          "description": "Reference number unique to a Permit",
          "type": "string"
        },
        "promoter_swa_code": {
          "description": "Street Works Act (SWA) code of the organisation carrying out the work",
          "type": "string"
        },
        "promoter_organisation": {
          "description": "Name of the organisation carrying out the work",
          "type": "string"
        },
        "highway_authority": {
          "description": "Name of the organisation responsible for the area where the work/activity/section 58 is taking place",
          "type": "string"
        },
        "highway_authority_swa_code": {
          "description": "Street Works Act (SWA) code of the organisation responsible for the area where the work/activity/section 58 is taking place",
          "type": "string"
        },
        "works_location_coordinates": {
          "description": "Location of the work in GeoJSON format using BNG (British National Grid EPSG:27700)",
          "type": "string"
        },
        "usrn": {
          "description": "Unique Street Reference Number (USRN)",
          "type": "string"
        },
        "street_name": {
          "description": "Name of the street where the work/activity/section 58 is taking place as per NSG (National Street Gazetteer)",
          "type": "string"
        },
        "area_name": {
          "description": "Name of the area where the work/activity/section 58 is taking place as per NSG (National Street Gazetteer)",
          "type": "string"
        },
        "town": {
          "description": "Name of the town where the work/activity/section 58 is taking place as per NSG (National Street Gazetteer)",
          "type": [
            "string",
            "null"
          ]
        },
        "work_category": {
          "description": "Category of the work. Categories: Minor, Standard, Major, Major(PAA), Immediate - urgent, Immediate - emergency, HS2 (Highway)",
          "type": "string"
        },
        "traffic_management_type": {
          "description": "How traffic will be managed while work/activity is taking place. Types: Road closure, Contra-flow, Lane closure, Multi-way signals, Two-way signals, Convoy workings, Stop/go boards, Temporary obstruction 15 minute delay, Priority working, Give and take, Some carriageway incursion, No carriageway incursion",
          "type": "string"
        },
        "proposed_start_date": {
          "description": "The date the work is proposed to start",
          "type": "string",
          "format": "date-time"
        },
        "proposed_end_date": {
          "description": "The date the work is proposed to end",
          "type": "string",
          "format": "date-time"
        },
        "proposed_start_time": {
          "description": "The time the work is proposed to start. Undefined if not provided by the promoter.",
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "proposed_end_time": {
          "description": "The time the work is proposed to end. Undefined if not provided by the promoter.",
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "actual_start_date_time": {
          "description": "The date & time the work started",
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "actual_end_date_time": {
          "description": "The date & time the work ended",
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "work_status": {
          "description": "Status of the work.",
          "type": "string",
          "enum": [
            "Works planned",
            "Works in progress",
            "Works completed",
            "Works cancelled",
            "Unattributable works",
            "Historical works",
            "Non notifiable works",
            "Section 81 works"
          ]
        },
        "work_category_ref": {
          "description": "(API Reference) Category of the work.",
          "type": "string",
          "enum": [
            "minor",
            "standard",
            "major",
            "immediate_urgent",
            "immediate_emergency",
            "paa",
            "hs2_highway"
          ]
        },
        "traffic_management_type_ref": {
          "description": "(API Reference) How traffic will be managed while work is taking place.",
          "type": "string",
          "enum": [
            "road_closure",
            "contra_flow",
            "lane_closure",
            "multi_way_signals",
            "two_way_signals",
            "convoy_workings",
            "stop_go_boards",
            "temp_obstruction_15_minute_delay",
            "priority_working",
            "give_and_take",
            "some_carriageway_incursion",
            "no_carriageway_incursion"
          ]
        },
        "work_status_ref": {
          "description": "(API Reference) Status of the work.",
          "type": "string",
          "enum": [
            "planned",
            "in_progress",
            "completed",
            "cancelled",
            "unattributable",
            "historical",
            "non_notifiable",
            "section_81"
          ]
        },
        "is_ttro_required": {
          "description": "Is a temporary traffic regulation order required?",
          "type": "string",
          "enum": [
            "Yes",
            "No",
            "Not provided"
          ]
        },
        "is_covid_19_response": {
          "description": "Is the work in response to Covid 19",
          "type": "string",
          "enum": [
            "Yes",
            "No"
          ]
        },
        "works_location_type": {
          "description": "Comma separated list of the type of location where the work is taking place. Types: Footway, Carriageway, Verge, Cycleway, Footpath, Parking place, Bus stop or stand, Cycle hire docking station, Taxi rank",
          "type": "string"
        },
        "permit_conditions": {
          "description": "Comma separated list of the Condition codes which are applicable to the work. Condition codes: NCT01a, NCT01b, NCT02a, NCT02b, NCT04a, NCT04b, NCT05a, NCT06a, NCT07a, NCT08a, NCT08b, NCT09a, NCT09b, NCT09c, NCT10a, NCT11a, NCT11b, NCT12a",
          "type": "string"
        },
        "is_traffic_sensitive": {
          "description": "Is work happening during traffic sensitive times.",
          "type": "string"
        },
        "is_deemed": {
          "description": "Did the work deem? (deadline date of the application passed before an assessment decision was submitted)",
          "type": "string",
          "enum": [
            "Yes",
            "No"
          ]
        },
        "permit_status": {
          "description": "(API Reference) Status of the permit. Status References: submitted, granted, permit_modification_request, refused, closed, cancelled, revoked, progressed",
          "type": "string",
          "enum": [
            "submitted",
            "granted",
            "permit_modification_request",
            "refused",
            "closed",
            "cancelled",
            "revoked",
            "progressed"
          ]
        },
        "collaboration_type": {
          "description": "Comma separated list of the collaboration types which are applicable to the work. Collaboration types: Trench sharing - primary promoter, Trench sharing - secondary promoter, Sharing traffic management only, Other",
          "type": "string"
        },
        "collaboration_type_ref": {
          "description": "(API Reference) Comma separated list of the collaboration_types which are applicable to the work. Collaboration_types: trench_sharing_primary_promoter, trench_sharing_secondary_promoter, sharing_traffic_management_only, other",
          "type": "string"
        },
        "close_footway": {
          "description": "Will the footway be closed?",
          "type": "string",
          "enum": [
            "Yes, a pedestrian walkway will be provided",
            "Yes, an alternative route will be provided",
            "No"
          ]
        },
        "close_footway_ref": {
          "description": "(API Reference) Will the footway be closed?",
          "type": "string",
          "enum": [
            "yes_provide_pedestrian_walkway",
            "yes_provide_alternative_route",
            "no"
          ]
        },
        "current_traffic_management_type": {
          "description": "How traffic is currently being managed while work/activity is taking place. Null if not provided",
          "type": "string",
          "enum": [
            "Road closure",
            "Contra-flow",
            "Lane closure",
            "Multi-way signals",
            "Two-way signals",
            "Convoy workings",
            "Stop/go boards",
            "Temporary obstruction 15 minute delay",
            "Priority working",
            "Give and take",
            "Some carriageway incursion",
            "No carriageway incursion"
          ]
        },
        "current_traffic_management_type_ref": {
          "description": "(API Reference) How traffic is currently being managed while work/activity is taking place. Null if not provided",
          "type": "string",
          "enum": [
            "road_closure",
            "contra_flow",
            "lane_closure",
            "multi_way_signals",
            "two_way_signals",
            "convoy_workings",
            "stop_go_boards",
            "temp_obstruction_15_minute_delay",
            "priority_working",
            "give_and_take",
            "some_carriageway_incursion",
            "no_carriageway_incursion"
          ]
        },
        "current_traffic_management_update_date": {
          "description": "The date the current traffic management type was updated. Null if not provided",
          "type": "string",
          "format": "date-time"
        },
        "activity_reference_number": {
          "description": "Reference number unique to an activity",
          "type": "string"
        },
        "road_category": {
          "description": "The category of the road where the work/activity is taking place as per NSG (National Street Gazetteer)",
          "type": "string",
          "enum": [
            "0",
            "1",
            "2",
            "3",
            "4",
            "5",
            "6",
            "7",
            "8",
            "9",
            "10"
          ]
        },
        "activity_coordinates": {
          "description": "Location of the activity in GeoJSON format using BNG (British National Grid EPSG:27700)",
          "type": "string"
        },
        "activity_name": {
          "description": "Name of the activity provided by the Highway Authority",
          "type": "string"
        },
        "activity_type": {
          "description": "Type of the activity being carried out during the work/activity",
          "type": "string"
        },
        "activity_type_details": {
          "description": "Details of event or licensed activity entered when activity type is 'Other'",
          "type": "string"
        },
        "start_date": {
          "description": "The date the activity will start",
          "type": "string",
          "format": "date-time"
        },
        "start_time": {
          "description": "The date/time the activity will start on. Undefined if not provided by Highway Authority.",
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "end_date": {
          "description": "The date the activity will end on",
          "type": "string",
          "format": "date-time"
        },
        "end_time": {
          "description": "The date/time the activity will end on. Undefined if not provided by Highway Authority.",
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "activity_location_type": {
          "description": "Type of location where the activity is taking place. Types: Footway, Carriageway, Verge, Cycleway, Footpath, Parking place, Bus stop or stand, Cycle hire docking station, Taxi rank",
          "type": "string"
        },
        "activity_location_description": {
          "description": "Free text description of the activity location",
          "type": "string"
        },
        "traffic_management_required": {
          "description": "'False' if traffic_management_type is no_carriageway_incursion or some_carriageway_incursion, otherwise 'True'",
          "type": "string"
        },
        "collaborative_working": {
          "description": "Will there be collaborative working during the work/activity?",
          "type": "string",
          "enum": [
            "Yes",
            "No"
          ]
        },
        "cancelled": {
          "description": "Has the activity been cancelled",
          "type": "string",
          "enum": [
            "Yes",
            "No"
          ]
        },
        "section_58_reference_number": {
          "description": "Reference number unique to a section 58",
          "type": "string"
        },
        "section_58_coordinates": {
          "description": "Location of the section 58 in GeoJSON format using BNG (British National Grid EPSG:27700)",
          "type": "string"
        },
        "section_58_status": {
          "description": "(API Reference) Status of the section 58. Status References: proposed, in_force, cancelled, closed",
          "type": "string",
          "enum": [
            "proposed",
            "in_force",
            "cancelled",
            "closed"
          ]
        },
        "section_58_duration": {
          "description": "(API Reference) Duration of the section 58. Duration References: six_months, one_year, two_years, three_years",
          "type": "string",
          "enum": [
            "six_months",
            "one_year",
            "two_years",
            "three_years"
          ]
        },
        "section_58_extent": {
          "description": "(API Reference) Extent of the section 58. Extent References: whole_road, part_of_the_road",
          "type": "string",
          "enum": [
            "whole_road",
            "part_of_the_road"
          ]
        },
        "section_58_location_type": {
          "description": "Type of location where the section 58 is taking place. Types: Footway, Carriageway, Verge, Cycleway, Footpath, Parking place, Bus stop or stand, Cycle hire docking station, Taxi rank",
          "type": "string"
        },
        "status_change_date": {
          "description": "The date the section 58 status was last changed",
          "type": "string",
          "format": "date-time"
        }
      }
    }
  },
  "properties": {
    "event_reference": {
      "description": "The unique reference for this event",
      "type": "integer"
    },
    "event_type": {
      "description": "The type of event",
      "type": "string",
      "enum": [
        "WORK_START",
        "WORK_STOP",
        "WORK_START_REVERTED",
        "WORK_STOP_REVERTED",
        "PERMIT_GRANTED",
        "PERMIT_ALTERATION_GRANTED",
        "PERMIT_CANCELLED",
        "PERMIT_REVOKED",
        "PERMIT_SUBMITTED",
        "PERMIT_REFUSED",
        "ACTIVITY_CREATED",
        "ACTIVITY_UPDATED",
        "ACTIVITY_CANCELLED",
        "SECTION_58_CREATED",
        "SECTION_58_IN_FORCE",
        "SECTION_58_CANCELLED",
        "SECTION_58_CLOSED",
        "CURRENT_TRAFFIC_MANAGEMENT_UPDATED"
      ]
    },
    "object_data": {
      "$ref": "#/definitions/object_data"
    },
    "event_time": {
      "description": "The time the event occurred and was submitted in Street Manager",
      "type": "string",
      "format": "date-time"
    },
    "object_type": {
      "description": "The type of object",
      "type": "string",
      "enum": [
        "PERMIT",
        "ACTIVITY",
        "SECTION_58"
      ]
    },
    "object_reference": {
      "description": "The reference number of the object",
      "type": "string"
    },
    "version": {
      "description": "The JSON schema version",
      "type": "integer"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "object_type": {
            "const": "PERMIT"
          }
        }
      },
      "then": {
        "properties": {
          "object_data": {
            "required": [
              "work_reference_number",
              "permit_reference_number",
              "promoter_swa_code",
              "promoter_organisation",
              "works_location_coordinates",
              "work_category",
              "traffic_management_type",
              "proposed_start_date",
              "proposed_start_time",
              "proposed_end_date",
              "proposed_end_time",
              "actual_start_date_time",
              "actual_end_date_time",
              "work_status",
              "work_category_ref",
              "traffic_management_type_ref",
              "work_status_ref",
              "activity_type",
              "is_ttro_required",
              "is_covid_19_response",
              "works_location_type",
              "permit_conditions",
              "road_category",
              "is_traffic_sensitive",
              "is_deemed",
              "permit_status",
              "collaborative_working",
              "collaboration_type",
              "collaboration_type_ref",
              "close_footway",
              "close_footway_ref",
              "current_traffic_management_type",
              "current_traffic_management_type_ref",
              "current_traffic_management_update_date"
            ],
            "properties": {
              "activity_type": {
                "enum": [
                  "Highway improvement works",
                  "Highway repair and maintenance works",
                  "Utility asset works",
                  "Utility repair and maintenance works",
                  "Diversionary works",
                  "Disconnection or alteration of supply",
                  "Permanent reinstatement",
                  "Remedial works",
                  "Section 58",
                  "Section 50",
                  "Core Sampling",
                  "Statutory Infrastructure Works",
                  "Works for Rail Purposes",
                  "Works for road purposes",
                  "New service connection",
                  "Optional permit (no fee) e.g. for traffic management etc"
                ]
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "object_type": {
            "const": "ACTIVITY"
          }
        }
      },
      "then": {
        "properties": {
          "object_data": {
            "required": [
              "activity_reference_number",
              "road_category",
              "activity_coordinates",
              "activity_name",
              "activity_type",
              "start_date",
              "start_time",
              "end_date",
              "end_time",
              "activity_location_type",
              "activity_location_description",
              "traffic_management_required",
              "traffic_management_type",
              "collaborative_working",
              "cancelled"
            ],
            "properties": {
              "activity_type": {
                "enum": [
                  "skips",
                  "scaffolding",
                  "hoarding",
                  "crane_mobile_platform",
                  "event",
                  "section50",
                  "section58",
                  "compound",
                  "other"
                ]
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "object_type": {
            "const": "SECTION_58"
          }
        }
      },
      "then": {
        "properties": {
          "object_data": {
            "required": [
              "section_58_reference_number",
              "section_58_coordinates",
              "section_58_status",
              "start_date",
              "end_date",
              "section_58_duration",
              "section_58_extent",
              "section_58_location_type",
              "status_change_date",
              "highway_authority_swa_code",
              "highway_authority",
              "usrn",
              "street_name",
              "area_name",
              "town"
            ]
          }
        }
      }
    }
  ],
  "required": [
    "event_reference",
    "event_type",
    "object_data",
    "event_time",
    "object_type",
    "object_reference",
    "version"
  ]
}