-- Pack 17 support SQL

INSERT INTO settings (setting_key, setting_value)
VALUES
('brand_app_name', 'GoPools CRM'),
('brand_logo', ''),
('brand_favicon', ''),
('theme_mode', 'light'),
('theme_primary', '#2563eb'),
('theme_secondary', '#0f172a'),
('theme_glass', '1'),
('background_type', 'gradient'),
('background_color', '#f8fafc'),
('background_image', ''),
('background_gradient', 'linear-gradient(135deg,#f8fafc 0%,#e2e8f0 100%)'),
('background_overlay_opacity', '0.10')
ON DUPLICATE KEY UPDATE setting_value = VALUES(setting_value);

ALTER TABLE users ADD COLUMN IF NOT EXISTS customer_id INT UNSIGNED NULL;
ALTER TABLE users MODIFY COLUMN role ENUM('admin','manager','employee','partner','customer') NOT NULL DEFAULT 'employee';
CREATE INDEX idx_users_customer_id ON users(customer_id);

CREATE TABLE IF NOT EXISTS project_sold_equipment (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    project_id INT UNSIGNED NOT NULL,
    customer_id INT UNSIGNED NOT NULL,
    item_name VARCHAR(255) NOT NULL,
    brand VARCHAR(190) NULL,
    model VARCHAR(190) NULL,
    serial_number VARCHAR(190) NULL,
    purchase_date DATE NULL,
    warranty_start DATE NULL,
    warranty_end DATE NULL,
    supplier_name VARCHAR(190) NULL,
    notes TEXT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (id),
    KEY idx_project_sold_equipment_project (project_id),
    KEY idx_project_sold_equipment_customer (customer_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
