CREATE TABLE IF NOT EXISTS `tronado_transactions` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `user_id` bigint(20) NOT NULL,
  `payment_id` varchar(255) NOT NULL,
  `token` varchar(255) DEFAULT NULL,
  `payment_url` text DEFAULT NULL,
  `usd_amount` decimal(18,8) NOT NULL,
  `amount_toman` bigint(20) NOT NULL,
  `tron_amount` decimal(18,8) NOT NULL,
  `estimated_toman_amount` varchar(64) DEFAULT NULL,
  `status` enum('pending','paid','failed') NOT NULL DEFAULT 'pending',
  `hash` varchar(255) DEFAULT NULL,
  `raw_callback` longtext DEFAULT NULL,
  `raw_verify` longtext DEFAULT NULL,
  `created_at` int(11) NOT NULL,
  `paid_at` int(11) DEFAULT NULL,
  UNIQUE KEY `payment_id` (`payment_id`),
  KEY `user_id` (`user_id`),
  KEY `status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;


ALTER TABLE `payments`
MODIFY `tron_amount` DECIMAL(16,5) DEFAULT 0.00000;


CREATE TABLE IF NOT EXISTS `xui_services` (
`id` bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`user_id` bigint(20) NOT NULL,
`inbound_id` int(11) NOT NULL,
`email` varchar(255) NOT NULL,
`uuid` varchar(64) NOT NULL,
`traffic_gb` int(11) NOT NULL,
`price_usd` decimal(18,2) NOT NULL,
`expiry_time` bigint(20) NOT NULL,
`config_link` text DEFAULT NULL,
`sub_link` text DEFAULT NULL,
`status` enum('active','disabled','expired') NOT NULL DEFAULT 'active',
`raw_response` longtext DEFAULT NULL,
`created_at` int(11) NOT NULL,
KEY `user_id` (`user_id`),
KEY `email` (`email`),
KEY `uuid` (`uuid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

ALTER TABLE `xui_services` ADD COLUMN `sub_link` text DEFAULT NULL AFTER `config_link`;
