-- LICENSE SERVER DATABASE
-- Aapke server par yeh database banayein
-- Database naam: rto_licenses

CREATE DATABASE IF NOT EXISTS rto_licenses CHARACTER SET utf8 COLLATE utf8_general_ci;
USE rto_licenses;

CREATE TABLE IF NOT EXISTS licenses (
    id                INT AUTO_INCREMENT PRIMARY KEY,
    license_key       VARCHAR(20) UNIQUE NOT NULL,
    customer_name     VARCHAR(100) NOT NULL,
    customer_email    VARCHAR(150) NOT NULL,
    plan              VARCHAR(30) DEFAULT 'standard',
    status            ENUM('active','revoked','suspended') DEFAULT 'active',
    registered_domain VARCHAR(255) DEFAULT NULL,
    expires_at        DATE DEFAULT NULL,
    note              TEXT,
    check_count       INT DEFAULT 0,
    first_used_at     DATETIME DEFAULT NULL,
    last_checked_at   DATETIME DEFAULT NULL,
    created_at        DATETIME DEFAULT NULL
);

CREATE TABLE IF NOT EXISTS license_logs (
    id          INT AUTO_INCREMENT PRIMARY KEY,
    license_key VARCHAR(20),
    domain      VARCHAR(255),
    ip          VARCHAR(45),
    result      VARCHAR(30),
    checked_at  DATETIME DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_key (license_key),
    INDEX idx_time (checked_at)
);
