-- [CONTROLS]

CREATE TYPE CONTROLS_1_PREP AS ENUM ('ABOVE', 'BELOW');

-- LINK  linkID  status  IF NODE   nodeID  ABOVE / BELOW   value
CREATE TABLE CONTROLS_1
(
  LinkID VARCHAR(32) PRIMARY KEY REFERENCES _LINK(ID)
, Status TEXT NOT NULL -- OPEN / CLOSED, a pump speed setting, or a control valve setting
, NodeID VARCHAR(32) REFERENCES _NODE(ID) NOT NULL
, Prep CONTROLS_1_PREP NOT NULL
, Value NUMERIC NOT NULL
);

--  LINK linkID   status   AT TIME  time
CREATE TABLE CONTROLS_2
(
  LinkID VARCHAR(32) PRIMARY KEY REFERENCES _LINK(ID)
, Status TEXT NOT NULL -- OPEN / CLOSED, a pump speed setting, or a control valve setting
, Time INTERVAL HOUR
);

--  LINK linkID   status   AT CLOCKTIME clocktime   AM / PM
CREATE TABLE CONTROLS_3
(
  LinkID VARCHAR(32) PRIMARY KEY REFERENCES _LINK(ID)
, Status TEXT NOT NULL -- OPEN / CLOSED, a pump speed setting, or a control valve setting
, Clock_Time_Hour INTERVAL HOUR -- get AM/PM from it
, Clock_Time_Min  INTERVAL MINUTE
);
