-- Phase 13 — lead scoring: adds score column to leads table and a
-- lead_score_events table for auditing which signals contributed to a score.
-- Idempotent: all alterations wrapped in IF NOT EXISTS / MODIFY guards.

ALTER TABLE leads
    MODIFY COLUMN status ENUM('new','open','replied','converted','closed') NOT NULL DEFAULT 'new';

-- score: 0-100 integer. NULL = never calculated yet.
-- MySQL 8.x does not support ADD COLUMN IF NOT EXISTS (MariaDB extension).
-- Migration runner ensures this file only runs once, so plain ADD COLUMN is safe.
ALTER TABLE leads
    ADD COLUMN score TINYINT UNSIGNED NULL DEFAULT NULL AFTER status,
    ADD COLUMN score_updated_at DATETIME NULL DEFAULT NULL AFTER score;
