-- basic information of bay

-- DROP TABLE IF EXISTS PUBLIC.BAY;

CREATE TABLE PUBLIC.BAY (
    BAY_UUID UUID PRIMARY KEY DEFAULT GEN_RANDOM_UUID(),
  	NAME VARCHAR(64) NOT NULL DEFAULT '',
  	TYPE VARCHAR(64) NOT NULL DEFAULT '',
    UNOM DOUBLE PRECISION NOT NULL DEFAULT -1,
    FLA DOUBLE PRECISION NOT NULL DEFAULT -1,
    CAPACITY DOUBLE PRECISION NOT NULL DEFAULT -1,
    DESCRIPTION VARCHAR(512) NOT NULL DEFAULT '',
    IN_SERVICE BOOLEAN NOT NULL DEFAULT FALSE,
    STATE INTEGER NOT NULL DEFAULT -1,
    GRID VARCHAR(64) NOT NULL DEFAULT '',
    ZONE VARCHAR(64) NOT NULL DEFAULT '',
    STATION VARCHAR(64) NOT NULL DEFAULT '',
    BUSINESS JSONB NOT NULL DEFAULT '{}', -- {"unom":0.0,"bus_connected":""}
  	FROM_UUIDS JSONB NOT NULL DEFAULT '[]', -- uuids
  	TO_UUIDS JSONB NOT NULL DEFAULT '[]', -- uuids
    DEV_PROTECT JSONB NOT NULL DEFAULT '[]', -- devices
    DEV_FAULT_RECORD JSONB NOT NULL DEFAULT '[]', -- devices
    DEV_STATUS JSONB NOT NULL DEFAULT '[]', -- devices
    DEV_DYN_SENSE JSONB NOT NULL DEFAULT '[]', -- devices
    DEV_INSTRUCT JSONB NOT NULL DEFAULT '[]', -- devices
    DEV_ETC JSONB NOT NULL DEFAULT '[]', -- devices
    COMPONENTS UUID[] NOT NULL DEFAULT '{}',
	  OP INTEGER NOT NULL DEFAULT -1,
    TS TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP 
);