<?php
/*
dev: https://factweb.ir
channel telegram : @factwebir
*/
error_reporting(0);
include "config.php";
define('API_KEY',$API_KC); 

// Create user table
$connect->query("CREATE TABLE IF NOT EXISTS user (
  id bigint(64) PRIMARY KEY,
  step text NOT NULL,
  step2 text NOT NULL,
  step3 text NOT NULL,
  spam varchar(20) NOT NULL,
  vip varchar(5) DEFAULT NULL,
  expire varchar(50) DEFAULT NULL,
  groupvip varchar(5) DEFAULT NULL,
  groupvipexpire varchar(100) DEFAULT NULL,  
  name varchar(100) DEFAULT NULL,
  dl int(10) DEFAULT NULL,
  lng varchar(5) DEFAULT NULL,
  step4 text DEFAULT NULL,
  used_titles text DEFAULT NULL
)");

// Create settings table  
$connect->query("CREATE TABLE IF NOT EXISTS settings (
  botid varchar(30) PRIMARY KEY,
  bot_mode varchar(20) NOT NULL,
  forall varchar(20) NOT NULL,
  sendall varchar(20) NOT NULL,
  tedad varchar(20) NOT NULL,
  text text NOT NULL,
  chat_id varchar(20) NOT NULL,
  sendedit varchar(20) NOT NULL,
  is_all varchar(20) NOT NULL,
  factwebir varchar(20) NOT NULL,
  msg_id varchar(20) NOT NULL,
  modebot varchar(5) DEFAULT NULL,
  freedl int(10) DEFAULT NULL,
  commandhelp varchar(50) DEFAULT NULL,
  commandbuy varchar(50) DEFAULT NULL,
  vazaitads varchar(5) DEFAULT NULL,
  placeads varchar(10) DEFAULT NULL,
  alljoin int(10) DEFAULT NULL,
  lngcommand varchar(100) DEFAULT NULL,
  startfa text DEFAULT NULL,
  starten text DEFAULT NULL,
  startar text DEFAULT NULL,
  startru text DEFAULT NULL,
  pton varchar(20) DEFAULT NULL,  
  ptron varchar(20) DEFAULT NULL,
  pdolar varchar(20) DEFAULT NULL,
  startdu text DEFAULT NULL,
  starttu text DEFAULT NULL, 
  startch text DEFAULT NULL,
  startin text DEFAULT NULL,
  startfr text DEFAULT NULL,
  startsp text DEFAULT NULL,
  commandsearch varchar(100) DEFAULT NULL,
  searchenginner varchar(20) DEFAULT NULL,
  voicesearch varchar(5) DEFAULT NULL,
  videosearch varchar(5) DEFAULT NULL,
  inlinesearch varchar(5) DEFAULT NULL,
  textsearch varchar(5) DEFAULT NULL,
  instagram_status varchar(5) DEFAULT 'on',
  youtube_status varchar(5) DEFAULT 'on',
  twitter_status varchar(5) DEFAULT 'on',
  threads_status varchar(5) DEFAULT 'on',
  tiktok_status varchar(5) DEFAULT 'on',
  pinterest_status varchar(5) DEFAULT 'on'
)");

// Create channels table
$connect->query("CREATE TABLE IF NOT EXISTS channels (
  idoruser varchar(100) PRIMARY KEY,
  link varchar(200) NOT NULL,
  type varchar(10) DEFAULT NULL  
)");

// Create additional tables
$connect->query("CREATE TABLE IF NOT EXISTS admins (
  idadmin varchar(20) PRIMARY KEY,
  nameadmin varchar(100) DEFAULT NULL
)");

$connect->query("CREATE TABLE IF NOT EXISTS ads (
  id int(10) PRIMARY KEY AUTO_INCREMENT,
  type varchar(10) DEFAULT NULL,
  file_id varchar(300) DEFAULT NULL,
  caption text DEFAULT NULL
)");  

$connect->query("CREATE TABLE IF NOT EXISTS groups (
   id int(10) PRIMARY KEY AUTO_INCREMENT,
   userid varchar(20) DEFAULT NULL,
   groupid varchar(40) DEFAULT NULL,
   limitreq varchar(20) DEFAULT NULL,
   search_query text DEFAULT NULL,
   search_source varchar(20) DEFAULT NULL,
   search_page int(11) DEFAULT 0,
   used_titles text DEFAULT NULL,
   lng varchar(10) DEFAULT NULL,
   commandsend varchar(5) DEFAULT NULL,
   commandautolink varchar(5) DEFAULT NULL,
   commandautomedia varchar(5) DEFAULT NULL
)");

$connect->query("CREATE TABLE IF NOT EXISTS helps (
   id int(10) PRIMARY KEY AUTO_INCREMENT,
   name varchar(100) DEFAULT NULL,
   file_id varchar(200) DEFAULT NULL,
   type varchar(50) DEFAULT NULL,
   caption text DEFAULT NULL,
   lang varchar(2) DEFAULT NULL  
)");

$connect->query("CREATE TABLE IF NOT EXISTS peyment (
  id int(10) PRIMARY KEY AUTO_INCREMENT,
  merichentzarin text DEFAULT NULL,
  merichentzib text DEFAULT NULL,
  wallettron text DEFAULT NULL,
  typepay varchar(20) DEFAULT NULL,
  vaztron varchar(5) DEFAULT NULL,
  vazonlinepay varchar(5) DEFAULT NULL,
  walletton text DEFAULT NULL,
  vazton varchar(10) DEFAULT NULL
)");

$connect->query("CREATE TABLE IF NOT EXISTS subs (
  id int(10) PRIMARY KEY AUTO_INCREMENT,
  namesub text DEFAULT NULL,
  days int(10) DEFAULT NULL,
  price int(20) DEFAULT NULL,
  typesub varchar(10) DEFAULT NULL
)");

$connect->query("CREATE TABLE IF NOT EXISTS wallet (
  id int(10) PRIMARY KEY AUTO_INCREMENT,  
  user_id varchar(150) DEFAULT NULL,
  private_key text DEFAULT NULL,
  address_base58 text DEFAULT NULL
)");

$connect->query("CREATE TABLE IF NOT EXISTS pays (
  id int(11) PRIMARY KEY AUTO_INCREMENT,
  user_id varchar(30) NOT NULL,
  amount int(11) NOT NULL,
  order_id varchar(20) NOT NULL,
  sub_id varchar(200) NOT NULL,
  status enum('pending','completed') NOT NULL DEFAULT 'pending',
  created_at varchar(50) NOT NULL,
  msgid int(20) DEFAULT NULL,
  KEY order_id (order_id),
  KEY user_id (user_id)  
)"); 

$connect->query("CREATE TABLE IF NOT EXISTS transactions (
  codecomment varchar(20) PRIMARY KEY,
  userid varchar(20) DEFAULT NULL,  
  priceton varchar(20) DEFAULT NULL,
  timeexpire varchar(100) DEFAULT NULL,
  sub_id varchar(20) DEFAULT NULL
)");

$connect->query("CREATE TABLE IF NOT EXISTS youtube_sessions (
  id int(11) PRIMARY KEY AUTO_INCREMENT,
  user_id bigint(20) NOT NULL,
  session_id varchar(255) NOT NULL,  
  email varchar(255) NOT NULL,
  created_at timestamp NOT NULL DEFAULT current_timestamp()  
)");

// Insert default settings if not exist
if($settings['botid'] == null) {
    $connect->query("INSERT INTO settings (botid, bot_mode, forall, sendall, tedad, text, chat_id, sendedit, is_all, factwebir, msg_id, modebot, freedl, commandhelp, commandbuy, vazaitads, placeads, alljoin, lngcommand, startfa, starten, startar, startru, pton, ptron, pdolar, startdu, starttu, startch, startin, startfr, startsp, commandsearch, searchenginner, voicesearch, videosearch, inlinesearch, textsearch, instagram_status, youtube_status, twitter_status, threads_status, tiktok_status, pinterest_status) 
    VALUES ('$botid', 'on', 'false', 'false', '0', 'none', '0', 'none', 'no', 'no', 'none', 'sub', 5, '/help', '/buy', 'off', 'after', 0, '/lng', 'start', 'start', 'start', 'start', '4.802', '0.24771', '83530', 'start', 'start', 'start', 'start', 'start', 'start', '/search', 'acr', 'on', 'on', 'on', 'on', 'on', 'on', 'on', 'on', 'on', 'on')");
    
    $connect->query("INSERT INTO `peyment` (`id`, `merichentzarin`, `merichentzib`, `wallettron`, `typepay`, `vaztron`, `vazonlinepay`, `walletton`, `vazton`) VALUES
(1, 'merichent', 'merichent', 'wallet tron', 'zarin', 'on', 'on', 'wallet ton', 'on');
");
    
}