-- Create the panel_info table
CREATE TABLE IF NOT EXISTS `panel_info` (
  `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `latest_version` varchar(20) NOT NULL,
  `latest_version_url` varchar(255) NOT NULL,
  `package_name` varchar(100) NOT NULL,
  `app_name` varchar(100) NOT NULL,
  `maintenance_mode` tinyint(1) NOT NULL DEFAULT 0,
  `admin_message` text,
  `src_price` varchar(20) NOT NULL,
  `src_buy_url` varchar(255) NOT NULL,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Insert sample data
INSERT INTO `panel_info` (`latest_version`, `latest_version_url`, `package_name`, `app_name`, `maintenance_mode`, `admin_message`, `src_price`, `src_buy_url`)
VALUES
('1.0.0', 'https://panel.obsidianff.com/download/ObsidianFF.apk', 'com.dts.ffobsidian', 'OBSIDIAN FF', 0, 'Welcome to Obsidian FF panel!', '$50 USD', 'https://panel.obsidianff.com/buy/source'); 

-- Create adsetting table
CREATE TABLE IF NOT EXISTS `adsetting` (
  `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `numberof_ads` int(11) NOT NULL DEFAULT 3,
  `ad_mode` tinyint(1) NOT NULL DEFAULT 0,
  `rendomize` tinyint(1) NOT NULL DEFAULT 0,
  `keyvalue` int(11) NOT NULL DEFAULT 24,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Insert default ad settings
INSERT INTO `adsetting` (`numberof_ads`, `ad_mode`, `rendomize`, `keyvalue`)
VALUES
(3, 0, 0, 24);

-- Create loginkey table
CREATE TABLE IF NOT EXISTS `loginkey` (
  `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `deviceid` varchar(100) NOT NULL,
  `key` varchar(20) NOT NULL,
  `expire_datetime` datetime NOT NULL,
  `regerter_datetime` datetime NOT NULL,
  `status` tinyint(1) NOT NULL DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Add index for faster queries
CREATE INDEX `idx_deviceid` ON `loginkey` (`deviceid`);
CREATE INDEX `idx_key` ON `loginkey` (`key`);

-- Create contracts table for social media URLs
CREATE TABLE IF NOT EXISTS `contracts` (
  `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `yturl` varchar(255) DEFAULT NULL,
  `fburl` varchar(255) DEFAULT NULL,
  `tiktokurl` varchar(255) DEFAULT NULL,
  `tgurl` varchar(255) DEFAULT NULL,
  `tggrupurl` varchar(255) DEFAULT NULL,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Insert default social media URLs
INSERT INTO `contracts` (`yturl`, `fburl`, `tiktokurl`, `tgurl`, `tggrupurl`)
VALUES
('https://www.youtube.com/channel/obsidianff', 'https://www.facebook.com/obsidianff', 'https://www.tiktok.com/@obsidianff', 'https://t.me/obsidianff', 'https://t.me/obsidianffgroup'); 