CREATE TABLE IF NOT EXISTS lead_statuses (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    slug VARCHAR(50) NOT NULL UNIQUE,
    label VARCHAR(100) NOT NULL,
    sort_order INT NOT NULL DEFAULT 0,
    is_system TINYINT(1) NOT NULL DEFAULT 0,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO lead_statuses (slug, label, sort_order, is_system)
SELECT 'novo', 'Novo', 1, 1 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM lead_statuses WHERE slug = 'novo');
INSERT INTO lead_statuses (slug, label, sort_order, is_system)
SELECT 'em_contato', 'Em contato', 2, 1 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM lead_statuses WHERE slug = 'em_contato');
INSERT INTO lead_statuses (slug, label, sort_order, is_system)
SELECT 'proposta', 'Proposta', 3, 1 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM lead_statuses WHERE slug = 'proposta');
INSERT INTO lead_statuses (slug, label, sort_order, is_system)
SELECT 'fechado', 'Fechado', 4, 1 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM lead_statuses WHERE slug = 'fechado');
INSERT INTO lead_statuses (slug, label, sort_order, is_system)
SELECT 'perdido', 'Perdido', 5, 1 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM lead_statuses WHERE slug = 'perdido');
