CREATE TABLE lead_rvx_profiles (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    lead_id INT UNSIGNED NOT NULL,
    integration_id INT UNSIGNED NULL,
    cpf VARCHAR(20) NULL,
    benefit_number VARCHAR(30) NULL,
    benefit_state VARCHAR(5) NULL,
    personal_data JSON NULL,
    additional_data JSON NULL,
    last_synced_at DATETIME NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NULL,
    CONSTRAINT fk_rvx_profiles_lead FOREIGN KEY (lead_id) REFERENCES leads (id) ON DELETE CASCADE,
    CONSTRAINT fk_rvx_profiles_integration FOREIGN KEY (integration_id) REFERENCES api_integrations (id) ON DELETE SET NULL,
    UNIQUE KEY uq_rvx_profiles_lead (lead_id),
    INDEX idx_rvx_profiles_cpf (cpf),
    INDEX idx_rvx_profiles_benefit (benefit_number)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
