CREATE TYPE "PaymentMethod" AS ENUM (
    'pay_u',
    'payment_on_the_spot'
);

CREATE TYPE "ShoppingCartState" AS ENUM (
    'active',
    'closed'
);

CREATE TYPE "QuantityUnit" AS ENUM (
    'g',
    'dkg',
    'kg',
    'piece'
);

CREATE TABLE shopping_carts (
    id serial NOT NULL,
    buyer_id integer NOT NULL,
    payment_method "PaymentMethod" DEFAULT 'payment_on_the_spot'::"PaymentMethod" NOT NULL,
    state "ShoppingCartState" DEFAULT 'active'::"ShoppingCartState" NOT NULL,
    checkout_notes text
);

CREATE TABLE shopping_cart_items (
    id serial NOT NULL,
    product_id integer NOT NULL,
    shopping_cart_id integer,
    quantity integer DEFAULT 0 NOT NULL,
    quantity_unit "QuantityUnit" NOT NULL,
    CONSTRAINT positive_quantity CHECK ((quantity >= 0))
);
