-- Copyright (c) 1997-now, NeoNova BV, The Netherlands. All rights Reserved.
--
-- This software is the copyrighted work of NeoNova BV.
-- Use of the software is subject to the general business terms and conditions of NeoNova BV
-- and its related transaction documents like license sheets or other written notices.#
-- Any reproduction or redistribution of the software not in accordance with the license terms
-- is expressly prohibited by law, and may result in severe civil and criminally penalties.
-- Violators will be prosecuted to the maximum extent possible.

BEGIN;

CREATE TABLE parkinglot (
 id serial,

 created timestamp with time zone not null default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Creation Date
--HELP_EN_LONG:The date and time this record was created.
--HELP_NL_INFO:Datum aanmaak
--HELP_NL_LONG:De tijd en datum waarop dit is aangemaakt.

 lastupdate timestamp with time zone not null default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Last Update
--HELP_EN_LONG:The date and time this record was updated.
--HELP_NL_INFO:Laatste wijziging
--HELP_NL_LONG:De tijd en datum van laatste wijziging.

 company integer NOT NULL default '1',
--HELP_EN_INFO:company
--HELP_EN_LONG:The company this parkinglot belongs to.
--HELP_NL_INFO:bedrijf
--HELP_NL_LONG:Het bedrijf waar deze gegevens bij horen.

 status varchar(8) NOT NULL default 'active'
   CHECK (status IN ('active', 'deleted')),
--HELP_EN_INFO:status
--HELP_EN_LONG:The status of the parkinglot box.
--HELP_NL_INFO:status
--HELP_NL_LONG:Status van dit parkeervlak.

 phoneline integer NOT NULL default '1',
--HELP_EN_INFO: Extension
--HELP_EN_LONG: The extension for the parkinglot. 
--HELP_NL_INFO: Extensie
--HELP_NL_LONG: Het nummer (extensie) van dit parkeervlak. 

 name varchar(32) NOT NULL default '',
--HELP_EN_INFO:parkinglot name
--HELP_EN_LONG:The name for this parkinglot.
--HELP_NL_INFO:naam parkeervlak
--HELP_NL_LONG:De naam van dit parkeervlak.

 lastused timestamp,
--HELP_EN_INFO: Last used
--HELP_EN_LONG: The date on which the parkinglot was last used. 
--HELP_NL_INFO: Laatst gebruikt
--HELP_NL_LONG: De datum dat het parkeervlak voor het laatst is gebruikt. 

 first varchar(16) not NULL default '',
--HELP_EN_INFO: First extension
--HELP_EN_LONG: The extension of the first parking slot
--HELP_NL_INFO: Eerste extensie
--HELP_NL_LONG: De extensie van het eerste vak in dit parkeervlak

 last varchar(16) not NULL default '',
--HELP_EN_INFO: Last extension
--HELP_EN_LONG: The extension of the last parking slot.
--HELP_NL_INFO: Laatste extensie
--HELP_NL_LONG: De extensie van het laatste vak in dit parkeervlak

 maxtime integer default '60',
--HELP_EN_INFO:maximum parkinglot time
--HELP_EN_LONG:Maximum time that a caller can be waiting in the parkinglot. The minimum is 10 seconds.
--HELP_NL_INFO:maximum wachttijd
--HELP_NL_LONG:De maximale tijd dat iemand in het parkeervlak kan staan. Het minimum is 10 seconden.

 description varchar(256) not NULL default '',
--HELP_EN_INFO: Description
--HELP_EN_LONG: A description of the parkinglot.
--HELP_NL_INFO: Omschrijving
--HELP_NL_LONG: Geef een omschrijving voor dit parkeervlak. 

 PRIMARY KEY  (id)
);

GRANT UPDATE, SELECT, INSERT, DELETE ON parkinglot TO astium;
GRANT UPDATE, SELECT, INSERT, DELETE ON parkinglot_id_seq TO astium;
INSERT INTO parkinglot (status, description) VALUES ('deleted', 'empty');

ALTER TABLE parkinglot ADD CONSTRAINT parkinglot_phoneline_constraint FOREIGN KEY (phoneline) REFERENCES phoneline (id);

COMMIT;
