CREATE TABLE company (
    id SERIAL PRIMARY KEY,
    name VARCHAR NOT NULL,
    street VARCHAR,
    house_number VARCHAR,
    zip_code VARCHAR,
    city VARCHAR
);

CREATE TABLE "user" (
    id SERIAL PRIMARY KEY,
    login VARCHAR NOT NULL,
    password VARCHAR NOT NULL,
    full_name VARCHAR,
    email VARCHAR,
    admin bool,
    get_emails bool
);

CREATE TABLE property (
    id SERIAL PRIMARY KEY,
    name VARCHAR NOT NULL,
    description VARCHAR,
    price NUMERIC(9, 2) NOT NULL
);

CREATE TYPE message_type AS ENUM ('NewReservation', 'NewReservationCust', 'ReservationApp', 'ReservationCanceled');

CREATE TABLE message (
    id SERIAL PRIMARY KEY,
    msg_type message_type NOT NULL ,
    subject VARCHAR NOT NULL ,
    "text" TEXT NOT NULL
);

CREATE TABLE opening_hour (
    id SERIAL PRIMARY KEY,
    day INTEGER NOT NULL ,
    "from" TIME NOT NULL ,
    "to" TIME NOT NULL,
    discount INTEGER
);

CREATE TABLE customer (
    id BIGSERIAL PRIMARY KEY,
    full_name VARCHAR NOT NULL,
    email VARCHAR NOT NULL,
    phone VARCHAR,
    discount INTEGER
);

CREATE TYPE reservation_state AS ENUM ('New', 'Approved', 'Canceled');

CREATE TABLE reservation_sum (
    id BIGSERIAL PRIMARY KEY,
    uuid uuid NOT NULL,
    date DATE NOT NULL,
    customer BIGINT REFERENCES customer(id) NOT NULL,
    price NUMERIC(9, 2) NOT NULL,
    state reservation_state
);


CREATE TABLE reservation (
    id BIGSERIAL PRIMARY KEY,
    "from" TIME NOT NULL,
    "to" TIME NOT NULL,
    property INTEGER REFERENCES property(id) NOT NULL,
    summary BIGINT REFERENCES reservation_sum(id) NOT NULL
);
