


CREATE TABLE users(
      id SERIAL PRIMARY KEY,
      username VARCHAR(50) NOT NULL UNIQUE,
      password VARCHAR(100) NOT NULL,
      email VARCHAR(100)
);



CREATE TABLE menu_items (
     id SERIAL PRIMARY KEY,
     name VARCHAR(100) NOT NULL,
     description TEXT,
     price NUMERIC(10, 2) NOT NULL CHECK (price > 0),
     category VARCHAR(50)
);


CREATE TABLE orders (
     id SERIAL PRIMARY KEY,
     user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
     created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
     total_price NUMERIC(10, 2) NOT NULL CHECK (total_price >= 0)
);



CREATE TABLE order_details (
     id SERIAL PRIMARY KEY,
     order_id INTEGER NOT NULL REFERENCES orders(id) ON DELETE CASCADE,
     menu_item_id INTEGER NOT NULL REFERENCES menu_items(id),
     quantity INTEGER NOT NULL CHECK (quantity > 0),
     price NUMERIC(10, 2) NOT NULL CHECK (price > 0)
);


INSERT INTO menu_items (name, description, price, category)
VALUES
    ('Pizza', 'Cheese pizza with tomato sauce', 12.50, 'Pizza'),
    ('Burger', 'Beef burger with fries', 9.00, 'Burger'),
    ('Pasta', 'Pasta with Alfredo sauce', 11.00, 'Pasta'),
    ('Cola', 'Cold soft drink', 2.50, 'Drink');

SELECT * FROM users;
SELECT * FROM menu_items;
SELECT * FROM orders;
SELECT * FROM order_details;



