CREATE TABLE "stop_lists" (
  "input" int PRIMARY KEY,
  "point_dm" varchar(255),
  "point_type" varchar(255),
  "point_name" varchar(255),
  "point_stateless" varchar(255),
  "point_stopId" int,
  "point_anytype" varchar(255),
  "point_sort" int,
  "point_quality" int,
  "point_best" int,
  "point_object" varchar(255),
  "point_ref_id" int,
  "point_ref_gid" varchar(50),
  "point_ref_omc" int,
  "point_ref_placeID" int,
  "point_ref_place" varchar(50),
  "point_ref_coords" varchar(50),
  "itdOdvAssignedStops_stopid" int,
  "itdOdvAssignedStops_name" varchar(255),
  "itdOdvAssignedStops_x" float,
  "itdOdvAssignedStops_y" float,
  "itdOdvAssignedStops_mapName" varchar(255),
  "itdOdvAssignedStops_value" varchar(255),
  "itdOdvAssignedStops_place" varchar(255),
  "itdOdvAssignedStops_nameWithPlace" varchar(255),
  "itdOdvAssignedStops_distanceTime" int,
  "itdOdvAssignedStops_isTransferStop" int,
  "itdOdvAssignedStops_vm" int,
  "itdOdvAssignedStops_gid" varchar(255),
  "meta_lastModificationDate" timestamp
);

CREATE TABLE "serving_lines" (
  "servingLineId" uuid PRIMARY KEY,
  "mode_name" varchar(255),
  "mode_number" varchar(50),
  "mode_product" varchar(255),
  "mode_productId" int,
  "mode_type" int,
  "mode_code" int,
  "mode_destination" varchar(255),
  "mode_destID" int,
  "mode_desc" varchar(255),
  "mode_timetablePeriod" varchar(255),
  "diva_branch" varchar(50),
  "diva_line" varchar(50),
  "diva_supplement" varchar(50),
  "diva_dir" varchar(50),
  "diva_project" varchar(50),
  "diva_network" varchar(50),
  "diva_stateless" varchar(255),
  "diva_tripCode" int,
  "diva_operator" varchar(255),
  "diva_opPublicCode" varchar(50),
  "diva_opCode" varchar(50),
  "diva_Vf" date,
  "diva_vTo" date,
  "diva_lineDisplay" varchar(50),
  "meta_lastModificationDate" timestamp
);

CREATE TABLE "arrivals" (
  "depatureRequestId" uuid,
  "stopID" int,
  "x" float,
  "y" float,
  "mapName" varchar(255),
  "area" varchar(50),
  "platform" varchar(50),
  "platformName" varchar(255),
  "stopName" varchar(255),
  "nameWO" varchar(255),
  "pointType" varchar(50),
  "countdown" int,
  "arrivalTime" timestamp,
  "realArrivalTime" timestamp,
  "servingLine_key" varchar(255),
  "servingLine_code" varchar(50),
  "servingLine_number" varchar(50),
  "servingLine_symbol" varchar(50),
  "servingLine_motType" int,
  "servingLine_mtSubcode" int,
  "servingLine_realtime" boolean,
  "servingLine_direction" varchar(255),
  "servingLine_directionFrom" varchar(255),
  "servingLine_name" varchar(255),
  "servingLine_delay" int,
  "servingLine_liErgRiProj_line" varchar(255),
  "servingLine_liErgRiProj_project" varchar(255),
  "servingLine_liErgRiProj_direction" varchar(50),
  "servingLine_liErgRiProj_supplement" varchar(50),
  "servingLine_liErgRiProj_network" varchar(255),
  "servingLine_destID" varchar(255),
  "servingLine_stateless" varchar(255),
  "servingLine_lineDisplay" varchar(255),
  "operator_code" varchar(50),
  "operator_name" varchar(255),
  "operator_publicCode" varchar(50),
  "attrs_name" varchar(255),
  "attrs_value" varchar(255),
  primary key("stopID", "servingLine_key", "servingLine_stateless")
);

CREATE TABLE "depature_requests" (
  "depatureRequestId" uuid PRIMARY KEY,
  "stopid" int,
  "serverid" varchar(255),
  "requestid" varchar(255),
  "sessionid" varchar(255),
  "calcTime" float,
  "serverTime" timestamp,
  "logRequestId" varchar(255),
  unique ("depatureRequestId")
);

CREATE TABLE "station_hints" (
  "infoLinkURL" varchar(255) PRIMARY KEY,
  "infoLinkText" varchar(255),
  "infoText" varchar(2055)
);

CREATE TABLE "depature_requeststation_hints" (
  "infoLinkUrl" varchar(255) PRIMARY KEY,
  "depatureRequestId" uuid
);

CREATE TABLE "serving_line_depature_requests" (
  "depatureRequestId" uuid PRIMARY KEY,
  "servingLineId" uuid
);

ALTER TABLE "arrivals" ADD FOREIGN KEY ("depatureRequestId") REFERENCES "depature_requests" ("depatureRequestId");

--ALTER TABLE "depature_requests" ADD FOREIGN KEY ("stopid") REFERENCES "stop_lists" ("input");
--ALTER TABLE "stop_lists" ADD FOREIGN KEY ("input") REFERENCES "depature_requests" ("stopid");

ALTER TABLE "depature_requeststation_hints" ADD FOREIGN KEY ("infoLinkUrl") REFERENCES "station_hints" ("infoLinkURL");

ALTER TABLE "depature_requeststation_hints" ADD FOREIGN KEY ("depatureRequestId") REFERENCES "depature_requests" ("depatureRequestId");

ALTER TABLE "serving_line_depature_requests" ADD FOREIGN KEY ("depatureRequestId") REFERENCES "depature_requests" ("depatureRequestId");

ALTER TABLE "serving_line_depature_requests" ADD FOREIGN KEY ("servingLineId") REFERENCES "serving_lines" ("servingLineId");
