-- ============================================================
-- FoxxGuard Web Panel – schema.sql
-- Database structure for Web Panel Users & Registered Servers
-- ============================================================

CREATE DATABASE IF NOT EXISTS `foxxguard_panel` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE `foxxguard_panel`;

CREATE TABLE IF NOT EXISTS `ac_web_users` (
    `id`             INT AUTO_INCREMENT PRIMARY KEY,
    `username`       VARCHAR(50) UNIQUE NOT NULL,
    `password`       VARCHAR(255) NOT NULL,
    `discord_id`     VARCHAR(100) DEFAULT NULL,
    `license`        VARCHAR(255) DEFAULT NULL,
    `role`           VARCHAR(50) DEFAULT 'admin', -- 'superadmin', 'admin'
    `gemini_api_key` VARCHAR(255) DEFAULT NULL,   -- Personal Gemini API key for this account
    `created_at`     TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `ac_web_servers` (
    `id`             INT AUTO_INCREMENT PRIMARY KEY,
    `user_id`        INT NOT NULL,                -- Owner of the server reference
    `name`           VARCHAR(100) NOT NULL,       -- Human readable server name
    `api_url`        VARCHAR(255) NOT NULL,       -- e.g., http://localhost:30120 or public IP
    `api_token`      VARCHAR(255) NOT NULL,       -- Matches Config.ServerToken
    `created_at`     TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (`user_id`) REFERENCES `ac_web_users`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
