-- ================================================
-- Run this in cPanel phpMyAdmin
-- Database: YOUR_CPANEL_DB_NAME
-- ================================================

CREATE TABLE IF NOT EXISTS clients (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    email VARCHAR(100) NOT NULL DEFAULT '',
    license_key VARCHAR(64) UNIQUE NOT NULL,
    subscription_end DATE NOT NULL,
    max_machines INT DEFAULT 3,
    is_active TINYINT DEFAULT 1,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS machines (
    id INT AUTO_INCREMENT PRIMARY KEY,
    license_key VARCHAR(64) NOT NULL,
    machine_id VARCHAR(128) NOT NULL,
    registered_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    last_seen TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    UNIQUE KEY unique_machine (license_key, machine_id),
    INDEX idx_license (license_key)
);

CREATE TABLE IF NOT EXISTS config_store (
    id INT AUTO_INCREMENT PRIMARY KEY,
    license_key VARCHAR(64) NOT NULL,
    config_key VARCHAR(100) NOT NULL,
    config_value TEXT NOT NULL,
    UNIQUE KEY unique_config (license_key, config_key),
    INDEX idx_license (license_key)
);
