
-- Update products table to support new requirements
ALTER TABLE products 
    ADD COLUMN width DECIMAL(10,2) NULL,
    ADD COLUMN height DECIMAL(10,2) NULL,
    ADD COLUMN depth DECIMAL(10,2) NULL,
    ADD COLUMN brand VARCHAR(255) NULL,
    ADD COLUMN original_price DECIMAL(10,2) NULL,
    ADD COLUMN product_condition ENUM('New', 'Excellent', 'Good', 'Fair', 'Poor') NOT NULL DEFAULT 'Good',
    ADD COLUMN material VARCHAR(255) NULL,
    ADD COLUMN color VARCHAR(100) NULL,
    ADD COLUMN stock_status ENUM('in_stock', 'out_of_stock') NOT NULL DEFAULT 'in_stock',
    MODIFY COLUMN description LONGTEXT;

-- Create product_images table for multi-image support
CREATE TABLE IF NOT EXISTS product_images (
    id INT AUTO_INCREMENT PRIMARY KEY,
    product_id INT NOT NULL,
    image_url VARCHAR(500) NOT NULL,
    display_order INT DEFAULT 0,
    is_primary BOOLEAN DEFAULT FALSE,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE
);

-- Create product_categories junction table for multi-category support
CREATE TABLE IF NOT EXISTS product_categories (
    product_id INT NOT NULL,
    category_id INT NOT NULL,
    PRIMARY KEY (product_id, category_id),
    FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE,
    FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE CASCADE
);

-- Migrate existing single category to new join table if needed (optional cleanup)
-- INSERT INTO product_categories (product_id, category_id) SELECT id, category_id FROM products WHERE category_id IS NOT NULL;
