-- Migration pour la table InOut
CREATE TABLE IF NOT EXISTS InOut (
    id INT AUTO_INCREMENT PRIMARY KEY,
    product_id INT NOT NULL,
    type ENUM('in', 'out') NOT NULL,
    quantity INT NOT NULL,
    unit_price DECIMAL(10, 2),
    total_price DECIMAL(10, 2) GENERATED ALWAYS AS (quantity * unit_price) STORED,
    reason VARCHAR(255),
    reference VARCHAR(100),
    date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    created_by VARCHAR(50),
    FOREIGN KEY (product_id) REFERENCES Product(id) ON DELETE CASCADE,
    INDEX idx_inout_product (product_id),
    INDEX idx_inout_date (date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
