-- ============================================================================
-- QuickCatalog — Feature Additions Layer
-- ----------------------------------------------------------------------------
-- Everything built on top of the original QuickCatalog schema: Brands
-- section, PDF Brochure button, Stock Available quantity, and the sitewide
-- toggles that go with them. Baked directly into new stores from day one,
-- instead of relying on each feature's own runtime self-provisioning to
-- create it lazily on first use.
-- ============================================================================

-- ---- Brands section ----
CREATE TABLE IF NOT EXISTS `brands` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `brand_name` VARCHAR(255) NOT NULL,
    `brand_image` VARCHAR(255) DEFAULT NULL,
    `brand_url` VARCHAR(500) DEFAULT NULL,
    `sort_order` INT(11) NOT NULL DEFAULT 0,
    `status` TINYINT(1) NOT NULL DEFAULT 1,
    `created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `brand_settings` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `kicker_text`       VARCHAR(100) NOT NULL DEFAULT 'Trusted Brands',
    `title_text`        VARCHAR(150) NOT NULL DEFAULT 'Our Brands',
    `card_style`        VARCHAR(20)  NOT NULL DEFAULT 'card',
    `logo_effect`       VARCHAR(20)  NOT NULL DEFAULT 'grayscale_hover',
    `section_bg_type`   VARCHAR(10)  NOT NULL DEFAULT 'solid',
    `section_bg`        VARCHAR(9)   NOT NULL DEFAULT '#fafafb',
    `section_bg_2`      VARCHAR(9)   NOT NULL DEFAULT '#eef0fb',
    `card_bg`           VARCHAR(9)   NOT NULL DEFAULT '#ffffff',
    `heading_color`     VARCHAR(9)   NOT NULL DEFAULT '#1a1a2e',
    `kicker_color`      VARCHAR(9)   NOT NULL DEFAULT '#8a8a97',
    `carousel_nav_bg`   VARCHAR(9)   NOT NULL DEFAULT '#1a1a2e',
    `carousel_nav_icon` VARCHAR(9)   NOT NULL DEFAULT '#ffffff',
    `name_text_color`   VARCHAR(9)   NOT NULL DEFAULT '#43434e',
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `brand_settings` (`id`) VALUES (1);

-- Register "Our Brands" in the Home Settings visibility list, same as
-- every other homepage section (Testimonials, Why Choose Us, etc.)
INSERT INTO `home_sections` (`section_key`, `label`, `title`, `is_enabled`, `sort_order`)
VALUES ('brands', 'Our Brands', 'Our Brands', 1,
        (SELECT t.m FROM (SELECT COALESCE(MAX(sort_order),0)+1 AS m FROM home_sections) t));

-- ---- Products: PDF Brochure button + Stock Available quantity ----
ALTER TABLE `products`
    ADD COLUMN `enable_pdf`    TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Show Download PDF button on product page',
    ADD COLUMN `pdf_downloads` INT(11)    NOT NULL DEFAULT 0 COMMENT 'Times the PDF brochure was downloaded',
    ADD COLUMN `stock_qty`     INT(11)    NULL     DEFAULT NULL COMMENT 'Units available; NULL = not tracked';

-- ---- Site Settings: sitewide PDF button master switch ----
ALTER TABLE `setting`
    ADD COLUMN `enable_pdf_button` TINYINT(1) NOT NULL DEFAULT 1 COMMENT 'Master switch for the PDF button, overrides per-product setting';

-- ---- Site Settings: widen Address field (was VARCHAR(50), truncated real addresses) ----
ALTER TABLE `setting` MODIFY `address` TEXT NOT NULL;
