ALTER TABLE products
    ADD COLUMN mockup_prompt_template TEXT NULL AFTER base_spec_json;

ALTER TABLE shop_products
    ADD COLUMN inherit_mockup_prompt TINYINT NOT NULL DEFAULT 1 AFTER is_visible,
    ADD COLUMN mockup_prompt_override TEXT NULL AFTER override_settings_json;

CREATE TABLE IF NOT EXISTS mockup_generations (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    shop_product_id BIGINT UNSIGNED NOT NULL,
    source_product_id BIGINT UNSIGNED NULL,
    source_pdf_asset_id BIGINT UNSIGNED NULL,
    generated_asset_id BIGINT UNSIGNED NULL,
    provider VARCHAR(50) NOT NULL DEFAULT 'openai',
    model VARCHAR(120) NULL,
    prompt_origin VARCHAR(50) NOT NULL DEFAULT 'runtime',
    prompt_template TEXT NULL,
    prompt_override TEXT NULL,
    resolved_prompt LONGTEXT NOT NULL,
    status ENUM('success', 'failed') NOT NULL DEFAULT 'success',
    error_message TEXT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    generated_at DATETIME NULL,
    INDEX idx_mockup_generations_shop_product (shop_product_id),
    CONSTRAINT fk_mockup_generations_shop_product FOREIGN KEY (shop_product_id) REFERENCES shop_products(id),
    CONSTRAINT fk_mockup_generations_source_pdf_asset FOREIGN KEY (source_pdf_asset_id) REFERENCES shop_product_assets(id),
    CONSTRAINT fk_mockup_generations_generated_asset FOREIGN KEY (generated_asset_id) REFERENCES shop_product_assets(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
