{
  "Comment": "Extract Properties information from AddressBase Premium GML",
  "version": "1.0",
  "StartAt": "ExtractProperties",
  "States": {
    "ExtractProperties": {
      "Type": "Task",
      "InputPath": "$.property",
      "Resource": "module:flattenXmlFiles",
      "ResourceConfig": {
        "rootXMLElement": "BasicLandPropertyUnit",
        "pivotPath": "$..LandPropertyIdentifier",
        "headerMap": [
          ["@.lpiKey", "lpi_key", "string"],
          ["@.logicalStatus", "lpi_status", "number"],
          ["$.uprn", "uprn", "number"],
          ["$..udprn", "udprn", "number"],
          ["$.changeType", "changeType", "string"],
          ["$.blpuState", "state", "number"],
          ["$.blpuStateDate", "state_date", "date"],
          ["$.classificationMember[?(@.Classification.classScheme=='AddressBase Premium Classification Scheme')]..classificationCode", "class", "string"],
          ["$.parentUPRN", "parent_uprn", "number"],
          [{"select": "$.position.Point.pos", "transform":"ordnanceSurvey_eastingCoord"}, "x", "number"],
          [{"select": "$.position.Point.pos", "transform":"ordnanceSurvey_northingCoord"}, "y", "number"],
          [{"select": "$.positionLatLong.Point.pos", "transform":"ordnanceSurvey_latitudeCoord"}, "latitude", "number"],
          [{"select": "$.positionLatLong.Point.pos", "transform":"ordnanceSurvey_longitudeCoord"}, "longitude", "number"],
          ["$.rpc", "rpc", "number"],
          ["$.localCustodianCode", "local_custodian_code", "number"],
          ["$.country", "country", "string"],
          ["$.startDate", "la_start_date", "date"],
          ["$.lastUpdateDate", "last_update_date", "date"],
          ["$.entryDate", "entry_date", "date"],
          ["$..DeliveryPointAddress.organisationName.en", "rm_organisation_name", "string"],
          ["$..Organisation.organisation.en", "la_organisation", "string"],
          ["$..DeliveryPointAddress.departmentName.en", "department_name", "string"],
          ["$..Organisation.legalName.en", "legal_name", "string"],
          ["$..DeliveryPointAddress.subBuildingName.en", "sub_building_name", "string"],
          ["$..DeliveryPointAddress.buildingName.en", "building_name", "string"],
          ["$..DeliveryPointAddress.buildingNumber", "building_number", "string"],
          ["@.saoStartNumber", "sao_start_number", "string"],
          ["@.saoStartSuffix", "sao_start_suffix", "string"],
          ["@.saoEndNumber", "sao_end_number", "string"],
          ["@.saoEndSuffix", "sao_end_suffix", "string"],
          ["@.saoText..en", "sao_text", "string"],
          ["@.saoText..cy", "alt_language_sao_text", "string"],
          ["@.paoStartNumber", "pao_start_number", "string"],
          ["@.paoStartSuffix", "pao_start_suffix", "string"],
          ["@.paoEndNumber", "pao_end_number", "string"],
          ["@.paoEndSuffix", "pao_end_suffix", "string"],
          ["@.paoText..en", "pao_text", "string"],
          ["@.paoText..cy", "alt_language_pao_text", "string"],
          ["@.usrn", "usrn", "number"],
          ["@.usrnMatchIndicator", "usrn_match_indicator", "number"],
          ["@.areaName", "area_name", "string"],
          ["@.level", "level", "string"],
          ["@.officialFlag", "official_flag", "string"],
          ["$.applicationCrossReferenceMember[?(@.ApplicationCrossReference.source=='7666MA')]..crossReference", "os_address_toid", "string", "comment - 7666MA = OS MasterMap Address Layer 2 TOID"],
          ["$.applicationCrossReferenceMember[?(@.ApplicationCrossReference.source=='7666MA')]..version", "os_address_toid_version", "number"],
          ["$.applicationCrossReferenceMember[?(@.ApplicationCrossReference.source=='7666MI')]..crossReference", "os_road_link_toid", "string", "comment - 7666MI = OS MasterMap Integrated Transport Network TOID."],
          ["$.applicationCrossReferenceMember[?(@.ApplicationCrossReference.source=='7666MI')]..version", "os_road_link_toid_version", "number"],
          ["$.applicationCrossReferenceMember[?(@.ApplicationCrossReference.source=='7666MT')]..crossReference", "os_topo_toid", "string", "comment - 7666MT = OS MasterMap Topography Layer TOID."],
          ["$.applicationCrossReferenceMember[?(@.ApplicationCrossReference.source=='7666MT')]..version", "os_topo_toid_version", "number"],
          ["$.applicationCrossReferenceMember[?(@.ApplicationCrossReference.source=='7666VC')]..crossReference", "voa_ct_record", "number", "comment - 7666VC = Centrally created Council Tax."],
          ["$.applicationCrossReferenceMember[?(@.ApplicationCrossReference.source=='7666VN')]..crossReference", "voa_ndr_record", "number", "comment - 7666VN = Centrally created non-domestic rates."],
          ["$..DeliveryPointAddress.dependentThoroughfare.en", "dependent_thoroughfare", "string"],
          ["$..DeliveryPointAddress.thoroughfare.en", "thoroughfare", "string"],
          ["$..DeliveryPointAddress.welshDependentThoroughfare.cy", "welsh_dependent_thoroughfare", "string"],
          ["$..DeliveryPointAddress.welshThoroughfare.cy", "welsh_thoroughfare", "string"],
          ["$..DeliveryPointAddress.doubleDependentLocality.en", "double_dependent_locality", "string"],
          ["$..DeliveryPointAddress.dependentLocality.en", "dependent_locality", "string"],
          ["$..DeliveryPointAddress.welshDoubleDependentLocality.cy", "welsh_double_dependent_locality", "string"],
          ["$..DeliveryPointAddress.welshDependentLocality.cy", "welsh_dependent_locality", "string"],
          ["$..DeliveryPointAddress.postTown.en", "post_town", "string"],
          ["$..DeliveryPointAddress.welshPostTown.cy", "welsh_post_town", "string"],
          ["$..DeliveryPointAddress.postcode", "postcode", "string"],
          ["$.postcodeLocator", "postcode_locator", "string"],
          ["$..DeliveryPointAddress.postcodeType", "postcode_type", "string"],
          ["$..DeliveryPointAddress.deliveryPointSuffix", "delivery_point_suffix", "string"],
          ["$.addressbasePostal", "addressbase_postal", "string"],
          ["$..DeliveryPointAddress.poBoxNumber", "po_box_number", "string"],
          ["$.applicationCrossReferenceMember[?(@.ApplicationCrossReference.source=='7666OW')]..crossReference", "ward_code", "string", "comment - 7666OW = ONS Ward Code."],
          ["$.applicationCrossReferenceMember[?(@.ApplicationCrossReference.source=='7666OP')]..crossReference", "parish_code", "string", "comment - 7666OP = ONS Parish Code."],
          ["$..DeliveryPointAddress.entryDate", "rm_start_date", "date"],
          ["$.multiOccCount", "multi_occ_count", "number"],
          ["$.classificationMember[?(@.Classification.classScheme=='VOA Primary Description')]..classificationCode", "voa_ndrp_desc_code", "string"],
          ["$.classificationMember[?(@.Classification.classScheme=='VOA Special Category')]..classificationCode", "voa_ndr_scat_code", "string"]
        ],
        "namespace": "strip",
        "xmllang": "wrap",
        "transform": "ordnanceSurvey_collapseMatchingLpis"
      },
      "End": true
    }
  },
  "restrictions": [
    {
      "roleId": "$authenticated",
      "allows": [
        "*"
      ]
    }
  ]
}
