-- Create database (if it doesn't exist)
CREATE DATABASE IF NOT EXISTS pickmyco_leads;

-- Use the database
USE pickmyco_leads;

-- Create leads table
CREATE TABLE IF NOT EXISTS leads (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    company VARCHAR(100) NOT NULL,
    email VARCHAR(100) NOT NULL,
    phone VARCHAR(20) NOT NULL,
    industry VARCHAR(50) NOT NULL,
    employees VARCHAR(20) NOT NULL,
    message TEXT,
    referral_source VARCHAR(100),
    campaign_data TEXT,
    date_submitted DATETIME NOT NULL,
    status ENUM('new', 'contacted', 'qualified', 'not_interested') DEFAULT 'new',
    notes TEXT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Create index for faster searching
CREATE INDEX idx_email ON leads(email);
CREATE INDEX idx_date ON leads(date_submitted);
CREATE INDEX idx_status ON leads(status);

-- Create a simple admin user for the admin panel
CREATE TABLE IF NOT EXISTS users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(50) NOT NULL UNIQUE,
    password VARCHAR(255) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Create a basic admin panel login (password should be hashed in real implementation)
-- Default credentials: admin/password123 (you should change these immediately)
INSERT INTO users (username, password) 
VALUES ('admin', '$2y$10$GkG2KdIZzJYcIz2hr3hM9eiAsPLM1jMeKl8DKWEJJVgLVmmwyxjtu')
ON DUPLICATE KEY UPDATE username=username;
