CREATE TABLE "Customer" (
  "cid" integer NOT NULL,
  "firstname" varchar NOT NULL,
  "lastname" varchar NOT NULL,
  "preference_vcid" integer NOT NULL,
  "preference_vcname" varchar NOT NULL,
  PRIMARY KEY ("cid", "firstname", "lastname")
	FOREIGN KEY ("preference_vcid") REFERENCES "VehicleClass" ("vcid");
	FOREIGN KEY ("preference_vcname") REFERENCES "VehicleClass" ("vcname");
);

CREATE TABLE "VehicleClass" (
  "vcid" integer NOT NULL,
  "vcname" varchar NOT NULL,
  "length" integer NOT NULL,
  "width" integer NOT NULL,
  "height" integer NOT NULL,
  PRIMARY KEY ("vcid", "vcname")
);

CREATE TABLE "Vehicle" (
  "vid" integer NOT NULL,
  "vcid" integer NOT NULL,
  "vcname" varchar NOT NULL,
  "last_check_date" datetime NOT NULL,
  "plate_num" integer,
  "street" varchar NOT NULL,
  "postcode" varchar NOT NULL,
  "city" varchar NOT NULL,
  "name" varchar NOT NULL,
  PRIMARY KEY ("vid", "vcid", "vcname", "street", "postcode", "city", "name")
	FOREIGN KEY ("vcid") REFERENCES "VehicleClass" ("vcid");
	FOREIGN KEY ("vcname") REFERENCES "VehicleClass" ("vcname");
	FOREIGN KEY ("street") REFERENCES "Station" ("street");
	FOREIGN KEY ("postcode") REFERENCES "Station" ("postcode");
	FOREIGN KEY ("city") REFERENCES "Station" ("city");
	FOREIGN KEY ("name") REFERENCES "Station" ("name");
);

CREATE TABLE "Station" (
  "street" varchar NOT NULL,
  "postcode" varchar NOT NULL,
  "city" varchar NOT NULL,
  "name" varchar NOT NULL,
  PRIMARY KEY ("street", "postcode", "city", "name")
);

CREATE TABLE "Reservation" (
  "startDateTime" datetime NOT NULL,
  "endDateTime" datetime NOT NULL,
  "frid" integer,
  "cid" integer NOT NULL,
  "cname" varchar NOT NULL,
  "vid" integer NOT NULL,
  PRIMARY KEY ("startDateTime", "cid", "cname", "vid")
	FOREIGN KEY ("frid") REFERENCES "FinishedReservation" ("frid");
	FOREIGN KEY ("cid") REFERENCES "Customer" ("cid");
	FOREIGN KEY ("cname") REFERENCES "Customer" ("firstname");
	FOREIGN KEY ("vid") REFERENCES "Vehicle" ("vid");
);

CREATE TABLE "FinishedReservation" (
	"frid" integer PRIMARY KEY NOT NULL,
	"distance" integer NOT NULL,
	"cost" integer NOT NULL
);
