-- ============================================
-- database.sql - License System Database Setup
-- ============================================

-- Create database
CREATE DATABASE IF NOT EXISTS license_system CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

USE license_system;

-- Create licenses table
CREATE TABLE IF NOT EXISTS licenses (
    id INT AUTO_INCREMENT PRIMARY KEY,
    license_key VARCHAR(255) UNIQUE NOT NULL,
    domain VARCHAR(255) NOT NULL,
    status ENUM('active', 'expired', 'suspended') DEFAULT 'active',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    expires_at TIMESTAMP NULL,
    last_verified TIMESTAMP NULL,
    INDEX idx_license_key (license_key),
    INDEX idx_domain (domain),
    INDEX idx_status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Insert sample data (optional - for testing)
-- INSERT INTO licenses (license_key, domain, status, expires_at) VALUES
-- ('12345678-ABCD1234-EFGH5678-IJKL9012', 'example.com', 'active', DATE_ADD(NOW(), INTERVAL 365 DAY)),
-- ('87654321-DCBA4321-HGFE8765-LKJI2109', 'testsite.com', 'active', NULL);