CREATE TABLE lead_effort_logs (
    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    lead_id INT UNSIGNED NOT NULL,
    user_id INT UNSIGNED NULL,
    role_snapshot VARCHAR(40) NULL,
    activity_type VARCHAR(60) NOT NULL,
    effort_minutes SMALLINT UNSIGNED NOT NULL,
    occurred_at DATETIME NOT NULL,
    metadata JSON NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NULL,
    CONSTRAINT fk_lead_effort_lead FOREIGN KEY (lead_id) REFERENCES leads (id) ON DELETE CASCADE,
    CONSTRAINT fk_lead_effort_user FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE SET NULL,
    INDEX idx_lead_effort_lead (lead_id),
    INDEX idx_lead_effort_occurred (occurred_at),
    INDEX idx_lead_effort_activity (activity_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
