CREATE TABLE lead_preapproved_banks (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    lead_id INT UNSIGNED NOT NULL,
    contract_data_id INT UNSIGNED NOT NULL,
    benefit_number VARCHAR(30) NULL,
    bank_id INT UNSIGNED NOT NULL,
    status ENUM('aprovado','pre_aprovado') NOT NULL,
    change_amount DECIMAL(15,2) NULL,
    source VARCHAR(20) NOT NULL DEFAULT 'RVX',
    evaluated_at DATETIME NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
    INDEX idx_preapproved_lead (lead_id),
    INDEX idx_preapproved_bank (bank_id),
    INDEX idx_preapproved_bank_lead (bank_id, lead_id),
    INDEX idx_preapproved_benefit (benefit_number),
    INDEX idx_preapproved_contract (contract_data_id),
    UNIQUE KEY idx_preapproved_unique (contract_data_id, bank_id, status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
