-- https://www.phpmyadmin.net/
--

START TRANSACTION;



--
-- Database: `fffstore_telegram_db`
--

-- --------------------------------------------------------

--
-- Table structure for table `apks`
--

CREATE TABLE `apks` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `bot_id` bigint(20) UNSIGNED NOT NULL,
  `title` varchar(160) NOT NULL,
  `version` varchar(80) DEFAULT NULL,
  `file_url` varchar(500) DEFAULT NULL,
  `description` text DEFAULT NULL,
  `status` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `bot_sessions`
--

CREATE TABLE `bot_sessions` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `bot_id` bigint(20) UNSIGNED NOT NULL,
  `telegram_user_id` bigint(20) NOT NULL,
  `state` varchar(100) NOT NULL,
  `payload` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`payload`)),
  `expires_at` datetime NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `bot_settings`
--

CREATE TABLE `bot_settings` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `bot_id` bigint(20) UNSIGNED NOT NULL,
  `setting_key` varchar(100) NOT NULL,
  `setting_value` text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `brands`
--

CREATE TABLE `brands` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `bot_id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(160) NOT NULL,
  `icon` varchar(20) DEFAULT NULL,
  `channel_link` varchar(500) DEFAULT NULL,
  `status` tinyint(1) NOT NULL DEFAULT 1,
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `brand_durations`
--

CREATE TABLE `brand_durations` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `brand_id` bigint(20) UNSIGNED NOT NULL,
  `label` varchar(80) NOT NULL,
  `duration_days` int(11) DEFAULT NULL,
  `duration_hours` int(11) DEFAULT NULL,
  `status` tinyint(1) NOT NULL DEFAULT 1,
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `brand_durations`
--

INSERT INTO `brand_durations` (`id`, `brand_id`, `label`, `duration_days`, `duration_hours`, `status`, `sort_order`, `created_at`) VALUES
(2, 2, 'trail', 1, 5, 1, 0, '2026-08-17 05:57:53'),
(3, 3, 'trail', 1, 5, 1, 0, '2026-08-17 10:08:05'),
(4, 3, '1 day', 1, 24, 1, 0, '2026-08-17 10:08:19');

-- --------------------------------------------------------

--
-- Table structure for table `brand_keys`
--

CREATE TABLE `brand_keys` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `bot_id` bigint(20) UNSIGNED NOT NULL,
  `brand_id` bigint(20) UNSIGNED NOT NULL,
  `duration_id` bigint(20) UNSIGNED DEFAULT NULL,
  `license_key` varchar(255) NOT NULL,
  `status` enum('available','sold','disabled') NOT NULL DEFAULT 'available',
  `sold_to_user_id` bigint(20) UNSIGNED DEFAULT NULL,
  `order_id` bigint(20) UNSIGNED DEFAULT NULL,
  `sold_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `brand_plans`
--

CREATE TABLE `brand_plans` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `brand_id` bigint(20) UNSIGNED NOT NULL,
  `duration_id` bigint(20) UNSIGNED DEFAULT NULL,
  `price` decimal(12,2) NOT NULL DEFAULT 0.00,
  `status` tinyint(1) NOT NULL DEFAULT 1,
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `brand_plans`
--

INSERT INTO `brand_plans` (`id`, `brand_id`, `duration_id`, `price`, `status`, `sort_order`, `created_at`, `updated_at`) VALUES
(1, 2, 2, 30.00, 1, 0, '2026-08-17 05:57:53', '2026-08-17 05:57:53'),
(2, 3, 3, 30.00, 1, 0, '2026-08-17 10:08:05', '2026-08-17 10:08:05'),
(3, 3, 4, 70.00, 1, 0, '2026-08-17 10:08:19', '2026-08-17 10:08:19');

-- --------------------------------------------------------

--
-- Table structure for table `broadcast_logs`
--

CREATE TABLE `broadcast_logs` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `bot_id` bigint(20) UNSIGNED NOT NULL,
  `message_text` text NOT NULL,
  `target_type` enum('all','paid') NOT NULL DEFAULT 'all',
  `sent_count` int(11) NOT NULL DEFAULT 0,
  `failed_count` int(11) NOT NULL DEFAULT 0,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `coupons`
--

CREATE TABLE `coupons` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `bot_id` bigint(20) UNSIGNED NOT NULL,
  `code` varchar(60) NOT NULL,
  `discount_type` enum('percent','fixed') NOT NULL DEFAULT 'percent',
  `discount_value` decimal(12,2) NOT NULL DEFAULT 0.00,
  `usage_limit` int(11) DEFAULT NULL,
  `used_count` int(11) NOT NULL DEFAULT 0,
  `expires_at` datetime DEFAULT NULL,
  `status` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `coupon_products`
--

CREATE TABLE `coupon_products` (
  `coupon_id` bigint(20) UNSIGNED NOT NULL,
  `product_id` bigint(20) UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `delivery_packages`
--

CREATE TABLE `delivery_packages` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `bot_id` bigint(20) UNSIGNED NOT NULL,
  `brand_id` bigint(20) UNSIGNED DEFAULT NULL,
  `title` varchar(180) NOT NULL,
  `apk_id` bigint(20) UNSIGNED DEFAULT NULL,
  `tutorial_id` bigint(20) UNSIGNED DEFAULT NULL,
  `include_paid_channel` tinyint(1) NOT NULL DEFAULT 0,
  `include_support` tinyint(1) NOT NULL DEFAULT 1,
  `status` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `license_keys`
--

CREATE TABLE `license_keys` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `product_id` bigint(20) UNSIGNED NOT NULL,
  `plan_id` bigint(20) UNSIGNED DEFAULT NULL,
  `license_key` varchar(255) NOT NULL,
  `status` enum('available','sold','disabled') NOT NULL DEFAULT 'available',
  `sold_to_user_id` bigint(20) UNSIGNED DEFAULT NULL,
  `order_id` bigint(20) UNSIGNED DEFAULT NULL,
  `sold_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `orders`
--

CREATE TABLE `orders` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `bot_id` bigint(20) UNSIGNED NOT NULL,
  `user_id` bigint(20) UNSIGNED NOT NULL,
  `product_id` bigint(20) UNSIGNED NOT NULL,
  `plan_id` bigint(20) UNSIGNED DEFAULT NULL,
  `license_key_id` bigint(20) UNSIGNED DEFAULT NULL,
  `payment_method` enum('wallet','upi') NOT NULL,
  `subtotal` decimal(12,2) NOT NULL DEFAULT 0.00,
  `discount` decimal(12,2) NOT NULL DEFAULT 0.00,
  `total` decimal(12,2) NOT NULL DEFAULT 0.00,
  `status` enum('pending','paid','failed','cancelled','refunded') NOT NULL DEFAULT 'pending',
  `payment_reference` varchar(150) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `paid_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `order_deliveries`
--

CREATE TABLE `order_deliveries` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `order_id` bigint(20) UNSIGNED NOT NULL,
  `payment_request_id` bigint(20) UNSIGNED DEFAULT NULL,
  `brand_key_id` bigint(20) UNSIGNED DEFAULT NULL,
  `delivery_package_id` bigint(20) UNSIGNED DEFAULT NULL,
  `delivered_at` datetime DEFAULT NULL,
  `delivery_status` enum('pending','delivered','failed') NOT NULL DEFAULT 'pending',
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `paid_channel_settings`
--

CREATE TABLE `paid_channel_settings` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `bot_id` bigint(20) UNSIGNED NOT NULL,
  `channel_username` varchar(150) DEFAULT NULL,
  `channel_url` varchar(500) DEFAULT NULL,
  `enabled` tinyint(1) NOT NULL DEFAULT 0,
  `required_for_purchase` tinyint(1) NOT NULL DEFAULT 0,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `payments`
--

CREATE TABLE `payments` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `bot_id` bigint(20) UNSIGNED NOT NULL,
  `user_id` bigint(20) UNSIGNED NOT NULL,
  `order_id` bigint(20) UNSIGNED DEFAULT NULL,
  `gateway` enum('upi','razorpay','cashfree','manual') NOT NULL DEFAULT 'upi',
  `amount` decimal(12,2) NOT NULL DEFAULT 0.00,
  `status` enum('created','paid','failed','expired') NOT NULL DEFAULT 'created',
  `gateway_order_id` varchar(180) DEFAULT NULL,
  `gateway_payment_id` varchar(180) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `paid_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `payment_requests`
--

CREATE TABLE `payment_requests` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `bot_id` bigint(20) UNSIGNED NOT NULL,
  `reseller_id` bigint(20) UNSIGNED DEFAULT NULL,
  `brand_id` bigint(20) UNSIGNED DEFAULT NULL,
  `brand_plan_id` bigint(20) UNSIGNED DEFAULT NULL,
  `user_id` bigint(20) UNSIGNED NOT NULL,
  `order_id` bigint(20) UNSIGNED NOT NULL,
  `amount` decimal(12,2) NOT NULL DEFAULT 0.00,
  `method` enum('upi','wallet') NOT NULL DEFAULT 'upi',
  `status` enum('pending','user_marked_paid','verified','rejected','expired','cancelled') NOT NULL DEFAULT 'pending',
  `reference_note` varchar(180) DEFAULT NULL,
  `proof_type` enum('none','utr','photo','document') NOT NULL DEFAULT 'none',
  `utr_reference` varchar(120) DEFAULT NULL,
  `proof_file_id` text DEFAULT NULL,
  `proof_chat_id` bigint(20) DEFAULT NULL,
  `proof_message_id` bigint(20) DEFAULT NULL,
  `proof_received_at` datetime DEFAULT NULL,
  `proof_deleted_at` datetime DEFAULT NULL,
  `marked_paid_at` datetime DEFAULT NULL,
  `verified_at` datetime DEFAULT NULL,
  `approved_at` datetime DEFAULT NULL,
  `rejected_at` datetime DEFAULT NULL,
  `reviewer_note` varchar(255) DEFAULT NULL,
  `verified_by` bigint(20) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `platform_admins`
--

CREATE TABLE `platform_admins` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `telegram_user_id` bigint(20) NOT NULL,
  `display_name` varchar(120) DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `platform_admins`
--

INSERT INTO `platform_admins` (`id`, `telegram_user_id`, `display_name`, `is_active`, `created_at`) VALUES
(1, 5348038519, 'Kunal', 1, '2026-08-16 16:05:18');

-- --------------------------------------------------------

--
-- Table structure for table `products`
--

CREATE TABLE `products` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `bot_id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(180) NOT NULL,
  `slug` varchar(180) NOT NULL,
  `description` text DEFAULT NULL,
  `image_url` varchar(500) DEFAULT NULL,
  `status` tinyint(1) NOT NULL DEFAULT 1,
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `product_plans`
--

CREATE TABLE `product_plans` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `product_id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(120) NOT NULL,
  `price` decimal(12,2) NOT NULL DEFAULT 0.00,
  `duration_label` varchar(60) DEFAULT NULL,
  `status` tinyint(1) NOT NULL DEFAULT 1,
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `product_plans`
--

INSERT INTO `product_plans` (`id`, `product_id`, `name`, `price`, `duration_label`, `status`, `sort_order`, `created_at`) VALUES
(1, 1, 'trail', 30.00, 'trail', 1, 0, '2026-08-17 07:14:27');

-- --------------------------------------------------------

--
-- Table structure for table `resellers`
--

CREATE TABLE `resellers` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(120) NOT NULL,
  `telegram_user_id` bigint(20) DEFAULT NULL,
  `phone` varchar(30) DEFAULT NULL,
  `status` enum('active','suspended','expired') NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `resellers`
--

INSERT INTO `resellers` (`id`, `name`, `telegram_user_id`, `phone`, `status`, `created_at`) VALUES
(7, 'SYCO', 8399011449, '9504429875', 'active', '2026-08-17 13:16:12'),
(8, 'BOSS OP', 1945889569, '9123699071', 'active', '2026-08-17 13:41:35');

-- --------------------------------------------------------

--
-- Table structure for table `reseller_admins`
--

CREATE TABLE `reseller_admins` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `reseller_id` bigint(20) UNSIGNED NOT NULL,
  `telegram_user_id` bigint(20) NOT NULL,
  `display_name` varchar(120) DEFAULT NULL,
  `role` enum('owner','admin') NOT NULL DEFAULT 'admin',
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `reseller_admins`
--

INSERT INTO `reseller_admins` (`id`, `reseller_id`, `telegram_user_id`, `display_name`, `role`, `is_active`, `created_at`) VALUES
(77, 7, 8399011449, 'SYCO', 'owner', 1, '2026-08-17 13:16:12'),
(82, 8, 1945889569, 'BOSS OP', 'owner', 1, '2026-08-17 13:41:35');

-- --------------------------------------------------------

--
-- Table structure for table `reseller_bot_ui_settings`
--

CREATE TABLE `reseller_bot_ui_settings` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `reseller_id` bigint(20) UNSIGNED NOT NULL,
  `paid_keys_enabled` tinyint(1) NOT NULL DEFAULT 1,
  `redeem_visible` tinyint(1) NOT NULL DEFAULT 1,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `reseller_bot_ui_settings`
--

INSERT INTO `reseller_bot_ui_settings` (`id`, `reseller_id`, `paid_keys_enabled`, `redeem_visible`, `updated_at`) VALUES
(1, 2, 1, 1, '2026-08-17 10:04:29');

-- --------------------------------------------------------

--
-- Table structure for table `reseller_delivery_settings`
--

CREATE TABLE `reseller_delivery_settings` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `reseller_id` bigint(20) UNSIGNED NOT NULL,
  `apk_url` varchar(500) DEFAULT NULL,
  `paid_channel_url` varchar(500) DEFAULT NULL,
  `tutorial_url` varchar(500) DEFAULT NULL,
  `support_url` varchar(500) DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `reseller_delivery_settings`
--

INSERT INTO `reseller_delivery_settings` (`id`, `reseller_id`, `apk_url`, `paid_channel_url`, `tutorial_url`, `support_url`, `updated_at`) VALUES
(6, 7, NULL, NULL, NULL, NULL, '2026-08-17 13:16:12'),
(7, 8, NULL, NULL, NULL, NULL, '2026-08-17 13:41:35');

-- --------------------------------------------------------

--
-- Table structure for table `reseller_subscriptions`
--

CREATE TABLE `reseller_subscriptions` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `reseller_id` bigint(20) UNSIGNED NOT NULL,
  `starts_at` datetime NOT NULL,
  `expires_at` datetime NOT NULL,
  `status` enum('active','expired','cancelled') NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `reseller_subscriptions`
--

INSERT INTO `reseller_subscriptions` (`id`, `reseller_id`, `starts_at`, `expires_at`, `status`, `created_at`) VALUES
(3, 8, '2026-08-17 13:58:29', '2026-09-16 13:58:29', 'cancelled', '2026-08-17 13:58:29'),
(4, 7, '2026-08-17 13:58:29', '2026-09-16 13:58:29', 'cancelled', '2026-08-17 13:58:29'),
(6, 7, '2026-08-17 13:59:05', '2026-09-16 13:59:05', 'cancelled', '2026-08-17 13:59:05'),
(7, 8, '2026-08-17 13:59:42', '2026-09-16 13:59:42', 'active', '2026-08-17 13:59:42'),
(8, 7, '2026-08-17 14:02:21', '2026-10-16 14:02:21', 'active', '2026-08-17 14:02:21');

-- --------------------------------------------------------

--
-- Table structure for table `support_settings`
--

CREATE TABLE `support_settings` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `bot_id` bigint(20) UNSIGNED NOT NULL,
  `support_username` varchar(120) DEFAULT NULL,
  `support_url` varchar(500) DEFAULT NULL,
  `support_text` text DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `telegram_users`
--

CREATE TABLE `telegram_users` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `bot_id` bigint(20) UNSIGNED NOT NULL,
  `telegram_user_id` bigint(20) NOT NULL,
  `username` varchar(120) DEFAULT NULL,
  `first_name` varchar(120) DEFAULT NULL,
  `last_name` varchar(120) DEFAULT NULL,
  `phone` varchar(30) DEFAULT NULL,
  `status` enum('active','blocked') NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `telegram_users`
--

INSERT INTO `telegram_users` (`id`, `bot_id`, `telegram_user_id`, `username`, `first_name`, `last_name`, `phone`, `status`, `created_at`, `updated_at`) VALUES
(4, 18, 5348038519, 'triple_f_modz', '🇹𝐑𝐈𝐏𝐋𝐄 🇫 ˢᵃᶠᵉ ᶫᵒᵃᵈᵉʳ ᵒʷⁿᵉʳ', NULL, NULL, 'active', '2026-08-17 11:12:30', '2026-08-17 11:12:30'),
(5, 18, 7775915912, 'kunal9925000', 'Swarit Gupta', NULL, NULL, 'active', '2026-08-17 11:12:53', '2026-08-17 11:12:53'),
(6, 18, 8399011449, 'Sycoloadr', '⁂⁙𐍃ℽcό⁙⁂꧂', NULL, NULL, 'active', '2026-08-17 11:46:48', '2026-08-17 11:46:48'),
(7, 19, 8399011449, 'Sycoloadr', '⁂⁙𐍃ℽcό⁙⁂꧂', NULL, NULL, 'active', '2026-08-17 13:19:51', '2026-08-17 13:19:51'),
(8, 19, 5348038519, 'triple_f_modz', '🇹𝐑𝐈𝐏𝐋𝐄 🇫 ˢᵃᶠᵉ ᶫᵒᵃᵈᵉʳ ᵒʷⁿᵉʳ', NULL, NULL, 'active', '2026-08-17 13:40:12', '2026-08-17 13:40:12'),
(9, 20, 5348038519, 'triple_f_modz', '🇹𝐑𝐈𝐏𝐋𝐄 🇫 ˢᵃᶠᵉ ᶫᵒᵃᵈᵉʳ ᵒʷⁿᵉʳ', NULL, NULL, 'active', '2026-08-17 13:42:24', '2026-08-17 13:42:24');

-- --------------------------------------------------------

--
-- Table structure for table `tutorials`
--

CREATE TABLE `tutorials` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `bot_id` bigint(20) UNSIGNED NOT NULL,
  `title` varchar(180) NOT NULL,
  `content` text DEFAULT NULL,
  `media_url` varchar(500) DEFAULT NULL,
  `status` tinyint(1) NOT NULL DEFAULT 1,
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `upi_settings`
--

CREATE TABLE `upi_settings` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `bot_id` bigint(20) UNSIGNED NOT NULL,
  `upi_id` varchar(180) DEFAULT NULL,
  `payee_name` varchar(180) DEFAULT NULL,
  `qr_image_url` varchar(500) DEFAULT NULL,
  `enabled` tinyint(1) NOT NULL DEFAULT 1,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `user_access_periods`
--

CREATE TABLE `user_access_periods` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `user_id` bigint(20) UNSIGNED NOT NULL,
  `bot_id` bigint(20) UNSIGNED NOT NULL,
  `starts_at` datetime NOT NULL,
  `expires_at` datetime NOT NULL,
  `source` varchar(80) DEFAULT NULL,
  `status` enum('active','expired','cancelled') NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `wallets`
--

CREATE TABLE `wallets` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `user_id` bigint(20) UNSIGNED NOT NULL,
  `balance` decimal(12,2) NOT NULL DEFAULT 0.00,
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `wallets`
--

INSERT INTO `wallets` (`id`, `user_id`, `balance`, `updated_at`) VALUES
(458, 4, 0.00, '2026-08-17 11:12:30'),
(459, 5, 0.00, '2026-08-17 11:12:53'),
(525, 6, 0.00, '2026-08-17 11:46:48'),
(597, 7, 0.00, '2026-08-17 13:19:51'),
(609, 8, 0.00, '2026-08-17 13:40:12'),
(621, 9, 0.00, '2026-08-17 13:42:24');

-- --------------------------------------------------------

--
-- Table structure for table `wallet_transactions`
--

CREATE TABLE `wallet_transactions` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `wallet_id` bigint(20) UNSIGNED NOT NULL,
  `type` enum('credit','debit','refund','adjustment') NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `balance_after` decimal(12,2) NOT NULL,
  `reason` varchar(255) DEFAULT NULL,
  `reference` varchar(120) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `apks`
--
ALTER TABLE `apks`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_apk_bot` (`bot_id`);

--
-- Indexes for table `bot_sessions`
--
ALTER TABLE `bot_sessions`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_bot_session_user` (`bot_id`,`telegram_user_id`),
  ADD KEY `idx_bot_sessions_expiry` (`expires_at`);

--
-- Indexes for table `bot_settings`
--
ALTER TABLE `bot_settings`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_bot_setting` (`bot_id`,`setting_key`);

--
-- Indexes for table `brands`
--
ALTER TABLE `brands`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_brand_bot_name` (`bot_id`,`name`),
  ADD KEY `idx_brands_bot_status` (`bot_id`,`status`,`sort_order`);

--
-- Indexes for table `brand_durations`
--
ALTER TABLE `brand_durations`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_brand_duration_label` (`brand_id`,`label`),
  ADD KEY `idx_brand_durations_brand_status` (`brand_id`,`status`,`sort_order`);

--
-- Indexes for table `brand_keys`
--
ALTER TABLE `brand_keys`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_brand_license_key` (`license_key`),
  ADD KEY `idx_brand_key_stock` (`bot_id`,`brand_id`,`duration_id`,`status`),
  ADD KEY `fk_brand_key_brand` (`brand_id`),
  ADD KEY `fk_brand_key_duration` (`duration_id`),
  ADD KEY `idx_brand_keys_available` (`bot_id`,`brand_id`,`duration_id`,`status`);

--
-- Indexes for table `brand_plans`
--
ALTER TABLE `brand_plans`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_brand_plan` (`brand_id`,`duration_id`),
  ADD KEY `fk_brand_plan_duration` (`duration_id`);

--
-- Indexes for table `broadcast_logs`
--
ALTER TABLE `broadcast_logs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_broadcast_bot` (`bot_id`,`created_at`);

--
-- Indexes for table `coupons`
--
ALTER TABLE `coupons`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_coupon_bot_code` (`bot_id`,`code`);

--
-- Indexes for table `coupon_products`
--
ALTER TABLE `coupon_products`
  ADD PRIMARY KEY (`coupon_id`,`product_id`),
  ADD KEY `fk_coupon_product_product` (`product_id`);

--
-- Indexes for table `delivery_packages`
--
ALTER TABLE `delivery_packages`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_delivery_bot_brand` (`bot_id`,`brand_id`),
  ADD KEY `fk_delivery_brand` (`brand_id`),
  ADD KEY `fk_delivery_apk` (`apk_id`),
  ADD KEY `fk_delivery_tutorial` (`tutorial_id`);

--
-- Indexes for table `license_keys`
--
ALTER TABLE `license_keys`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_license_key` (`license_key`),
  ADD KEY `idx_key_stock` (`product_id`,`plan_id`,`status`),
  ADD KEY `idx_key_user` (`sold_to_user_id`);

--
-- Indexes for table `orders`
--
ALTER TABLE `orders`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_order_bot_user` (`bot_id`,`user_id`,`created_at`),
  ADD KEY `fk_order_user` (`user_id`),
  ADD KEY `fk_order_product` (`product_id`),
  ADD KEY `fk_order_plan` (`plan_id`);

--
-- Indexes for table `order_deliveries`
--
ALTER TABLE `order_deliveries`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_order_delivery` (`order_id`),
  ADD KEY `fk_order_delivery_payment` (`payment_request_id`),
  ADD KEY `fk_order_delivery_key` (`brand_key_id`),
  ADD KEY `fk_order_delivery_package` (`delivery_package_id`);

--
-- Indexes for table `paid_channel_settings`
--
ALTER TABLE `paid_channel_settings`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_paid_channel_bot` (`bot_id`);

--
-- Indexes for table `payments`
--
ALTER TABLE `payments`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_payment_user` (`user_id`,`created_at`),
  ADD KEY `idx_payment_gateway_order` (`gateway_order_id`),
  ADD KEY `fk_payment_bot` (`bot_id`),
  ADD KEY `fk_payment_order` (`order_id`);

--
-- Indexes for table `payment_requests`
--
ALTER TABLE `payment_requests`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_payment_request_user` (`bot_id`,`user_id`,`status`),
  ADD KEY `idx_payment_request_order` (`order_id`),
  ADD KEY `fk_payment_request_user` (`user_id`),
  ADD KEY `idx_payment_requests_status` (`bot_id`,`status`,`created_at`),
  ADD KEY `idx_payment_requests_pending` (`bot_id`,`status`,`created_at`),
  ADD KEY `idx_payment_proof_status` (`bot_id`,`status`,`proof_type`,`created_at`),
  ADD KEY `idx_payment_requests_reseller_status` (`reseller_id`,`status`,`created_at`),
  ADD KEY `idx_payment_requests_brand_plan` (`brand_id`,`brand_plan_id`);

--
-- Indexes for table `platform_admins`
--
ALTER TABLE `platform_admins`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_platform_admin_telegram` (`telegram_user_id`);

--
-- Indexes for table `products`
--
ALTER TABLE `products`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_product_slug_bot` (`bot_id`,`slug`),
  ADD KEY `idx_product_bot` (`bot_id`);

--
-- Indexes for table `product_plans`
--
ALTER TABLE `product_plans`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_plan_product` (`product_id`),
  ADD KEY `idx_product_plans_active` (`product_id`,`status`);

--
-- Indexes for table `resellers`
--
ALTER TABLE `resellers`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_reseller_telegram` (`telegram_user_id`);

--
-- Indexes for table `reseller_admins`
--
ALTER TABLE `reseller_admins`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_reseller_admin_user` (`reseller_id`,`telegram_user_id`),
  ADD KEY `idx_reseller_admin_reseller` (`reseller_id`);

--
-- Indexes for table `reseller_bot_ui_settings`
--
ALTER TABLE `reseller_bot_ui_settings`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_ui_settings_reseller` (`reseller_id`);

--
-- Indexes for table `reseller_delivery_settings`
--
ALTER TABLE `reseller_delivery_settings`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_delivery_reseller` (`reseller_id`);

--
-- Indexes for table `reseller_subscriptions`
--
ALTER TABLE `reseller_subscriptions`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_subscription_reseller` (`reseller_id`),
  ADD KEY `idx_reseller_subscription_status_expiry` (`reseller_id`,`status`,`expires_at`);

--
-- Indexes for table `support_settings`
--
ALTER TABLE `support_settings`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_support_bot` (`bot_id`);

--
-- Indexes for table `telegram_users`
--
ALTER TABLE `telegram_users`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_tg_user_bot` (`bot_id`,`telegram_user_id`),
  ADD KEY `idx_tg_user_username` (`bot_id`,`username`);

--
-- Indexes for table `tutorials`
--
ALTER TABLE `tutorials`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_tutorial_bot` (`bot_id`);

--
-- Indexes for table `upi_settings`
--
ALTER TABLE `upi_settings`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_upi_bot` (`bot_id`);

--
-- Indexes for table `user_access_periods`
--
ALTER TABLE `user_access_periods`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_user_access` (`bot_id`,`user_id`,`expires_at`),
  ADD KEY `fk_access_user` (`user_id`);

--
-- Indexes for table `wallets`
--
ALTER TABLE `wallets`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_wallet_user` (`user_id`);

--
-- Indexes for table `wallet_transactions`
--
ALTER TABLE `wallet_transactions`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_wallet_tx_wallet` (`wallet_id`,`created_at`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `apks`
--
ALTER TABLE `apks`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `bot_sessions`
--
ALTER TABLE `bot_sessions`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=87;

--
-- AUTO_INCREMENT for table `bot_settings`
--
ALTER TABLE `bot_settings`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `brands`
--
ALTER TABLE `brands`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT for table `brand_durations`
--
ALTER TABLE `brand_durations`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

--
-- AUTO_INCREMENT for table `brand_keys`
--
ALTER TABLE `brand_keys`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=17;

--
-- AUTO_INCREMENT for table `brand_plans`
--
ALTER TABLE `brand_plans`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT for table `broadcast_logs`
--
ALTER TABLE `broadcast_logs`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `coupons`
--
ALTER TABLE `coupons`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `delivery_packages`
--
ALTER TABLE `delivery_packages`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `license_keys`
--
ALTER TABLE `license_keys`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `orders`
--
ALTER TABLE `orders`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=23;

--
-- AUTO_INCREMENT for table `order_deliveries`
--
ALTER TABLE `order_deliveries`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `paid_channel_settings`
--
ALTER TABLE `paid_channel_settings`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `payments`
--
ALTER TABLE `payments`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `payment_requests`
--
ALTER TABLE `payment_requests`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=22;

--
-- AUTO_INCREMENT for table `platform_admins`
--
ALTER TABLE `platform_admins`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `products`
--
ALTER TABLE `products`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `product_plans`
--
ALTER TABLE `product_plans`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `resellers`
--
ALTER TABLE `resellers`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;

--
-- AUTO_INCREMENT for table `reseller_admins`
--
ALTER TABLE `reseller_admins`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=83;

--
-- AUTO_INCREMENT for table `reseller_bot_ui_settings`
--
ALTER TABLE `reseller_bot_ui_settings`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT for table `reseller_delivery_settings`
--
ALTER TABLE `reseller_delivery_settings`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;

--
-- AUTO_INCREMENT for table `reseller_subscriptions`
--
ALTER TABLE `reseller_subscriptions`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;

--
-- AUTO_INCREMENT for table `support_settings`
--
ALTER TABLE `support_settings`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `telegram_users`
--
ALTER TABLE `telegram_users`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;

--
-- AUTO_INCREMENT for table `tutorials`
--
ALTER TABLE `tutorials`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `upi_settings`
--
ALTER TABLE `upi_settings`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `user_access_periods`
--
ALTER TABLE `user_access_periods`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `wallets`
--
ALTER TABLE `wallets`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=665;

--
-- AUTO_INCREMENT for table `wallet_transactions`
--
ALTER TABLE `wallet_transactions`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `apks`
--
ALTER TABLE `apks`
  ADD CONSTRAINT `fk_apk_bot` FOREIGN KEY (`bot_id`) REFERENCES `bots` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `bot_sessions`
--
ALTER TABLE `bot_sessions`
  ADD CONSTRAINT `fk_bot_session_bot` FOREIGN KEY (`bot_id`) REFERENCES `bots` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `bot_settings`
--
ALTER TABLE `bot_settings`
  ADD CONSTRAINT `fk_bot_setting_bot` FOREIGN KEY (`bot_id`) REFERENCES `bots` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `brands`
--
ALTER TABLE `brands`
  ADD CONSTRAINT `fk_brand_bot` FOREIGN KEY (`bot_id`) REFERENCES `bots` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `brand_durations`
--
ALTER TABLE `brand_durations`
  ADD CONSTRAINT `fk_brand_duration_brand` FOREIGN KEY (`brand_id`) REFERENCES `brands` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `brand_keys`
--
ALTER TABLE `brand_keys`
  ADD CONSTRAINT `fk_brand_key_bot` FOREIGN KEY (`bot_id`) REFERENCES `bots` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_brand_key_brand` FOREIGN KEY (`brand_id`) REFERENCES `brands` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_brand_key_duration` FOREIGN KEY (`duration_id`) REFERENCES `brand_durations` (`id`) ON DELETE SET NULL;

--
-- Constraints for table `brand_plans`
--
ALTER TABLE `brand_plans`
  ADD CONSTRAINT `fk_brand_plan_brand` FOREIGN KEY (`brand_id`) REFERENCES `brands` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_brand_plan_duration` FOREIGN KEY (`duration_id`) REFERENCES `brand_durations` (`id`) ON DELETE SET NULL;

--
-- Constraints for table `broadcast_logs`
--
ALTER TABLE `broadcast_logs`
  ADD CONSTRAINT `fk_broadcast_bot` FOREIGN KEY (`bot_id`) REFERENCES `bots` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `coupons`
--
ALTER TABLE `coupons`
  ADD CONSTRAINT `fk_coupon_bot` FOREIGN KEY (`bot_id`) REFERENCES `bots` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `coupon_products`
--
ALTER TABLE `coupon_products`
  ADD CONSTRAINT `fk_coupon_product_coupon` FOREIGN KEY (`coupon_id`) REFERENCES `coupons` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_coupon_product_product` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `delivery_packages`
--
ALTER TABLE `delivery_packages`
  ADD CONSTRAINT `fk_delivery_apk` FOREIGN KEY (`apk_id`) REFERENCES `apks` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `fk_delivery_bot` FOREIGN KEY (`bot_id`) REFERENCES `bots` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_delivery_brand` FOREIGN KEY (`brand_id`) REFERENCES `brands` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `fk_delivery_tutorial` FOREIGN KEY (`tutorial_id`) REFERENCES `tutorials` (`id`) ON DELETE SET NULL;

--
-- Constraints for table `orders`
--
ALTER TABLE `orders`
  ADD CONSTRAINT `fk_order_bot` FOREIGN KEY (`bot_id`) REFERENCES `bots` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_order_plan` FOREIGN KEY (`plan_id`) REFERENCES `product_plans` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `fk_order_product` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
  ADD CONSTRAINT `fk_order_user` FOREIGN KEY (`user_id`) REFERENCES `telegram_users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `order_deliveries`
--
ALTER TABLE `order_deliveries`
  ADD CONSTRAINT `fk_order_delivery_key` FOREIGN KEY (`brand_key_id`) REFERENCES `brand_keys` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `fk_order_delivery_order` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_order_delivery_package` FOREIGN KEY (`delivery_package_id`) REFERENCES `delivery_packages` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `fk_order_delivery_payment` FOREIGN KEY (`payment_request_id`) REFERENCES `payment_requests` (`id`) ON DELETE SET NULL;

--
-- Constraints for table `paid_channel_settings`
--
ALTER TABLE `paid_channel_settings`
  ADD CONSTRAINT `fk_paid_channel_bot` FOREIGN KEY (`bot_id`) REFERENCES `bots` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `payments`
--
ALTER TABLE `payments`
  ADD CONSTRAINT `fk_payment_bot` FOREIGN KEY (`bot_id`) REFERENCES `bots` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_payment_order` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `fk_payment_user` FOREIGN KEY (`user_id`) REFERENCES `telegram_users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `payment_requests`
--
ALTER TABLE `payment_requests`
  ADD CONSTRAINT `fk_payment_request_bot` FOREIGN KEY (`bot_id`) REFERENCES `bots` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_payment_request_order` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_payment_request_user` FOREIGN KEY (`user_id`) REFERENCES `telegram_users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `products`
--
ALTER TABLE `products`
  ADD CONSTRAINT `fk_product_bot` FOREIGN KEY (`bot_id`) REFERENCES `bots` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `product_plans`
--
ALTER TABLE `product_plans`
  ADD CONSTRAINT `fk_plan_product` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `reseller_admins`
--
ALTER TABLE `reseller_admins`
  ADD CONSTRAINT `fk_reseller_admin_reseller` FOREIGN KEY (`reseller_id`) REFERENCES `resellers` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `reseller_delivery_settings`
--
ALTER TABLE `reseller_delivery_settings`
  ADD CONSTRAINT `fk_delivery_reseller` FOREIGN KEY (`reseller_id`) REFERENCES `resellers` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `reseller_subscriptions`
--
ALTER TABLE `reseller_subscriptions`
  ADD CONSTRAINT `fk_subscription_reseller` FOREIGN KEY (`reseller_id`) REFERENCES `resellers` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `support_settings`
--
ALTER TABLE `support_settings`
  ADD CONSTRAINT `fk_support_bot` FOREIGN KEY (`bot_id`) REFERENCES `bots` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `telegram_users`
--
ALTER TABLE `telegram_users`
  ADD CONSTRAINT `fk_tg_user_bot` FOREIGN KEY (`bot_id`) REFERENCES `bots` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `tutorials`
--
ALTER TABLE `tutorials`
  ADD CONSTRAINT `fk_tutorial_bot` FOREIGN KEY (`bot_id`) REFERENCES `bots` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `upi_settings`
--
ALTER TABLE `upi_settings`
  ADD CONSTRAINT `fk_upi_bot` FOREIGN KEY (`bot_id`) REFERENCES `bots` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `user_access_periods`
--
ALTER TABLE `user_access_periods`
  ADD CONSTRAINT `fk_access_bot` FOREIGN KEY (`bot_id`) REFERENCES `bots` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_access_user` FOREIGN KEY (`user_id`) REFERENCES `telegram_users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `wallets`
--
ALTER TABLE `wallets`
  ADD CONSTRAINT `fk_wallet_user` FOREIGN KEY (`user_id`) REFERENCES `telegram_users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `wallet_transactions`
--
ALTER TABLE `wallet_transactions`
  ADD CONSTRAINT `fk_wallet_tx_wallet` FOREIGN KEY (`wallet_id`) REFERENCES `wallets` (`id`) ON DELETE CASCADE;
COMMIT;

