CREATE OR REPLACE VIEW
    user_details
AS SELECT
    addresses.user_id,
    users.first_name,
    users.last_name,
    users.username,
    addresses.id as "address_id",
    addresses.street_address,
    addresses.city,
    addresses.state,
    addresses.zip_code
FROM
    users
INNER JOIN
    addresses
ON
    addresses.user_id = users.id;

CREATE OR REPLACE VIEW
    order_details
AS SELECT
    addresses.user_id,
    users.first_name,
    users.last_name,
    users.username,
    addresses.id as "address_id",
    addresses.street_address,
    addresses.city,
    addresses.state,
    addresses.zip_code,
    orders.id as "order_id",
    order_items.product_id,
    order_items.quantity,
    products.name,
    products.price
FROM
    users
INNER JOIN orders ON orders.user_id = users.id
INNER JOIN addresses ON addresses.id = orders.address_id
INNER JOIN order_items ON order_items.order_id = orders.id
INNER JOIN products ON products.id = order_items.product_id;

CREATE OR REPLACE VIEW
    product_details
AS SELECT
    product_reviews.product_id,
    products.name,
    products.price,
    product_reviews.user_id,
    users.first_name,
    users.last_name,
    users.username,
    product_reviews.id AS "review_id",
    product_reviews.comment
FROM
    product_reviews
INNER JOIN
    products
ON
    products.id = product_reviews.product_id
INNER JOIN
    users
ON
    users.id = product_reviews.user_id;
