USE db_abos_v0.1;

CREATE TABLE IF NOT EXISTS fact_leads (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    tenant_id INT NOT NULL,
    business_id INT NULL,
    first_name VARCHAR(100) NOT NULL,
    last_name VARCHAR(100) NOT NULL,
    email VARCHAR(255) NULL,
    phone VARCHAR(50) NULL,
    company_name VARCHAR(255) NULL,
    source VARCHAR(100) NULL,
    status VARCHAR(50) NOT NULL DEFAULT 'New',
    score INT NULL,
    assigned_to INT NULL,
    notes TEXT NULL,
    created_at TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6),
    created_by INT NULL,
    updated_at TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    updated_by INT NULL,
    is_deleted TINYINT NOT NULL DEFAULT 0,
    INDEX idx_fact_leads_tenant (tenant_id),
    INDEX idx_fact_leads_status (tenant_id, status),
    INDEX idx_fact_leads_assigned (assigned_to)
);
