/*
BYRO Digital Asset Platform - Clean Database Initializer
Date: 2026-02-23
Instructions: Import this file into your MySQL/MariaDB database for a fresh start.
*/

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `admins`
--
DROP TABLE IF EXISTS `admins`;
CREATE TABLE `admins` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL,
  `password_hash` varchar(255) NOT NULL,
  `role` varchar(20) DEFAULT 'admin',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `is_agent` tinyint(4) DEFAULT 0,
  `permissions` text DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

LOCK TABLES `admins` WRITE;
INSERT INTO `admins` VALUES (1,'admin','$2y$10$uJvcqHNb.naRWj.apBapi.C.fF2zaIbMhYEtVdGmmVUWZkQi9ESfe','admin','2026-02-18 03:07:35',0,NULL);
UNLOCK TABLES;

--
-- Table structure for table `binary_orders`
--
DROP TABLE IF EXISTS `binary_orders`;
CREATE TABLE `binary_orders` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `symbol` varchar(20) NOT NULL,
  `direction` varchar(10) DEFAULT NULL,
  `amount` decimal(20,8) NOT NULL,
  `duration` int(11) NOT NULL,
  `profit_rate` decimal(5,2) NOT NULL,
  `entry_price` decimal(20,8) NOT NULL,
  `close_price` decimal(20,8) DEFAULT NULL,
  `status` enum('pending','won','lost','cancelled') DEFAULT 'pending',
  `control_status` tinyint(4) DEFAULT 0 COMMENT '0: normal, 1: force win, 2: force loss',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `ip_address` varchar(45) DEFAULT NULL,
  `end_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `chat_remarks`
--
DROP TABLE IF EXISTS `chat_remarks`;
CREATE TABLE `chat_remarks` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) DEFAULT 0,
  `ip_address` varchar(45) DEFAULT NULL,
  `session_id` varchar(255) DEFAULT NULL,
  `remark` text DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `user_id` (`user_id`,`ip_address`,`session_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `chat_visitors`
--
DROP TABLE IF EXISTS `chat_visitors`;
CREATE TABLE `chat_visitors` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) DEFAULT 0,
  `ip_address` varchar(45) DEFAULT NULL,
  `session_id` varchar(255) DEFAULT NULL,
  `last_ping` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `user_time` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `user_id` (`user_id`,`ip_address`),
  KEY `idx_session` (`session_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `contract_orders`
--
DROP TABLE IF EXISTS `contract_orders`;
CREATE TABLE `contract_orders` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `symbol` varchar(20) NOT NULL,
  `type` enum('limit','market') DEFAULT 'market',
  `direction` varchar(10) DEFAULT NULL,
  `leverage` int(11) DEFAULT 1,
  `amount` decimal(20,8) NOT NULL,
  `entry_price` decimal(20,8) DEFAULT NULL,
  `close_price` decimal(20,8) DEFAULT NULL,
  `status` enum('open','closed','cancelled') DEFAULT 'open',
  `profit` decimal(20,8) DEFAULT 0.00000000,
  `control_status` tinyint(4) DEFAULT 0 COMMENT '0: normal, 1: force win, 2: force loss',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `ip_address` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `exchange_records`
--
DROP TABLE IF EXISTS `exchange_records`;
CREATE TABLE `exchange_records` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `from_symbol` varchar(10) NOT NULL,
  `to_symbol` varchar(10) NOT NULL,
  `from_amount` decimal(20,8) NOT NULL,
  `to_amount` decimal(20,8) NOT NULL,
  `rate` decimal(20,8) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `ip_address` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `finance_requests`
--
DROP TABLE IF EXISTS `finance_requests`;
CREATE TABLE `finance_requests` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `type` enum('recharge','withdrawal') NOT NULL,
  `amount` decimal(20,8) NOT NULL,
  `symbol` varchar(10) DEFAULT 'USDT',
  `status` enum('0','3','4') DEFAULT '0',
  `payment_method` varchar(50) DEFAULT NULL,
  `payment_details` text DEFAULT NULL,
  `rejection_reason` text DEFAULT NULL,
  `tx_hash` varchar(255) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `ip_address` varchar(45) DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `fiat_amount` decimal(20,2) DEFAULT NULL,
  `fiat_currency` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `messages`
--
DROP TABLE IF EXISTS `messages`;
CREATE TABLE `messages` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) DEFAULT NULL,
  `admin_id` int(11) DEFAULT NULL,
  `sender` enum('user','admin') DEFAULT NULL,
  `message` text DEFAULT NULL,
  `ip_address` varchar(45) DEFAULT NULL,
  `session_id` varchar(255) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_session` (`session_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `price_controls`
--
DROP TABLE IF EXISTS `price_controls`;
CREATE TABLE `price_controls` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `symbol` varchar(20) NOT NULL,
  `target_price` decimal(20,8) NOT NULL,
  `execution_time` timestamp NOT NULL,
  `duration` int(11) DEFAULT 60 COMMENT 'seconds',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `spot_orders`
--
DROP TABLE IF EXISTS `spot_orders`;
CREATE TABLE `spot_orders` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `symbol` varchar(20) NOT NULL,
  `side` enum('buy','sell') NOT NULL,
  `price` decimal(20,8) DEFAULT NULL,
  `amount` decimal(20,8) NOT NULL,
  `filled` decimal(20,8) DEFAULT 0.00000000,
  `status` enum('0','filled','cancelled') DEFAULT '0',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `ip_address` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `staking_records`
--
DROP TABLE IF EXISTS `staking_records`;
CREATE TABLE `staking_records` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `plan_name` varchar(100) NOT NULL,
  `amount` decimal(20,8) NOT NULL,
  `total_profit` decimal(20,8) DEFAULT 0.00000000,
  `symbol` varchar(10) DEFAULT 'USDT',
  `daily_profit` decimal(5,2) NOT NULL,
  `period` int(11) NOT NULL COMMENT 'days',
  `status` enum('running','ended') DEFAULT 'running',
  `start_date` date NOT NULL,
  `end_date` date NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `last_settle_time` datetime DEFAULT NULL,
  `ip_address` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `system_settings`
--
DROP TABLE IF EXISTS `system_settings`;
CREATE TABLE `system_settings` (
  `setting_key` varchar(50) NOT NULL,
  `setting_value` text DEFAULT NULL,
  PRIMARY KEY (`setting_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

LOCK TABLES `system_settings` WRITE;
INSERT INTO `system_settings` VALUES 
('android_download_url','/downloads/byro.apk'),
('apk_download_url','/downloads/byro.apk'),
('email_verification_enabled','0'),
('ios_download_url','/downloads/byro.apk'),
('mail_from_email',''),
('mail_from_name','Byro Exchange'),
('service_link',''),
('site_favicon','/assets/images/favicon_byro_final.png'),
('site_logo','/assets/images/logo_byro_final.png'),
('site_name','BYRO'),
('smtp_host',''),
('smtp_pass',''),
('smtp_port','587'),
('smtp_secure','tls'),
('smtp_user',''),
('usdt_bep20_address','0x742d35Cc6634C0532925a3b844Bc454e4438f44e'),
('usdt_erc20_address','0x742d35Cc6634C0532925a3b844Bc454e4438f44e'),
('usdt_protocol','TRC20'),
('usdt_recharge_address',''),
('usdt_trc20_address','TYv9V5J1P1eEwz7y3WqJg9M2yv7f7xXv3x');
UNLOCK TABLES;

--
-- Table structure for table `transactions`
--
DROP TABLE IF EXISTS `transactions`;
CREATE TABLE `transactions` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `type` varchar(20) NOT NULL,
  `amount` decimal(20,8) NOT NULL,
  `symbol` varchar(10) NOT NULL,
  `status` varchar(20) DEFAULT 'completed',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `ip_address` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `user_balances`
--
DROP TABLE IF EXISTS `user_balances`;
CREATE TABLE `user_balances` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `symbol` varchar(10) NOT NULL,
  `available` decimal(20,8) DEFAULT 0.00000000,
  `frozen` decimal(20,8) DEFAULT 0.00000000,
  PRIMARY KEY (`id`),
  UNIQUE KEY `user_id` (`user_id`,`symbol`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `users`
--
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) DEFAULT NULL,
  `email` varchar(100) DEFAULT NULL,
  `password_hash` varchar(255) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `uid` varchar(20) DEFAULT NULL,
  `credit_score` int(11) DEFAULT 80,
  `real_name_status` int(11) DEFAULT 0,
  `role` varchar(20) DEFAULT 'user',
  `vip_level` int(11) DEFAULT 0,
  `total_recharge` decimal(16,4) DEFAULT 0.0000,
  `transaction_password` varchar(255) DEFAULT NULL,
  `kyc_name` varchar(100) DEFAULT NULL,
  `kyc_id_number` varchar(50) DEFAULT NULL,
  `kyc_photo_front` varchar(255) DEFAULT NULL,
  `kyc_photo_back` varchar(255) DEFAULT NULL,
  `kyc_photo_handheld` varchar(255) DEFAULT NULL,
  `kyc_status` int(11) DEFAULT 0 COMMENT '0: Unverified, 1: Pending, 2: Verified, 3: Rejected',
  `registration_ip` varchar(45) DEFAULT NULL,
  `status` enum('normal','frozen') DEFAULT 'normal',
  `win_loss_control` tinyint(4) DEFAULT 0 COMMENT '0: normal, 1: win, 2: loss',
  `remark` text DEFAULT NULL,
  `kyc_rejection_reason` text DEFAULT NULL,
  `agent_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`),
  UNIQUE KEY `email` (`email`),
  UNIQUE KEY `uid` (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
