CREATE TABLE lead_contract_data (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    lead_id INT UNSIGNED NOT NULL,
    original_bank_id INT UNSIGNED NULL,
    installment_amount DECIMAL(12,2) NULL,
    remaining_installments SMALLINT UNSIGNED NULL,
    original_term SMALLINT UNSIGNED NULL,
    outstanding_balance DECIMAL(13,2) NULL,
    evaluation_status VARCHAR(40) NULL,
    evaluation_message VARCHAR(255) NULL,
    evaluation_banks JSON NULL,
    evaluation_follow_up JSON NULL,
    evaluated_at DATETIME NULL,
    evaluated_by INT UNSIGNED NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NULL,
    CONSTRAINT fk_contract_data_lead FOREIGN KEY (lead_id) REFERENCES leads (id) ON DELETE CASCADE,
    CONSTRAINT fk_contract_data_bank FOREIGN KEY (original_bank_id) REFERENCES bank_catalog (id) ON DELETE SET NULL,
    CONSTRAINT fk_contract_data_user FOREIGN KEY (evaluated_by) REFERENCES users (id) ON DELETE SET NULL,
    INDEX idx_contract_data_lead (lead_id),
    INDEX idx_contract_data_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
