CREATE TABLE daycoval_catalog_entries (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    integration_id INT UNSIGNED NOT NULL,
    flow ENUM('refin','margem') NOT NULL,
    catalog_type VARCHAR(60) NOT NULL,
    code VARCHAR(120) NOT NULL,
    name VARCHAR(200) NULL,
    name_normalized VARCHAR(220) NULL,
    payload JSON NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
    CONSTRAINT fk_daycoval_catalog_integration FOREIGN KEY (integration_id) REFERENCES api_integrations (id) ON DELETE CASCADE,
    UNIQUE KEY uniq_daycoval_catalog (integration_id, flow, catalog_type, code),
    INDEX idx_daycoval_catalog_name (integration_id, flow, catalog_type, name_normalized)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
