-- phpMyAdmin SQL Dump
-- version 5.2.2
-- https://www.phpmyadmin.net/
--
-- Host: localhost:3306
-- Generation Time: Jun 05, 2026 at 04:33 PM
-- Server version: 10.11.16-MariaDB
-- PHP Version: 8.4.21

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!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 */;

--
-- Database: clean project install
--


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

--
-- Table structure for table `admin_chat_notes`
--

CREATE TABLE `admin_chat_notes` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `admin_id` bigint(20) DEFAULT NULL,
  `note_text` text NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `admin_logs`
--

CREATE TABLE `admin_logs` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `admin_user_id` bigint(20) NOT NULL,
  `admin_id` bigint(20) DEFAULT NULL,
  `action` varchar(100) NOT NULL,
  `target_type` varchar(100) DEFAULT NULL,
  `target_id` varchar(64) DEFAULT NULL,
  `details` longtext DEFAULT NULL,
  `old_value` longtext DEFAULT NULL,
  `new_value` longtext DEFAULT NULL,
  `ip_address` varchar(64) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `admin_private_messages`
--

CREATE TABLE `admin_private_messages` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `admin_id` bigint(20) DEFAULT NULL,
  `user_id` bigint(20) NOT NULL,
  `direction` varchar(30) NOT NULL DEFAULT 'admin_to_user',
  `message_text` longtext DEFAULT NULL,
  `telegram_message_id` bigint(20) DEFAULT NULL,
  `telegram_file_id` varchar(255) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `app_migrations`
--

CREATE TABLE `app_migrations` (
  `id` int(11) NOT NULL,
  `version` varchar(50) NOT NULL,
  `description` varchar(255) DEFAULT NULL,
  `applied_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `bot_user_states`
--

CREATE TABLE `bot_user_states` (
  `user_id` bigint(20) NOT NULL,
  `mode` varchar(100) NOT NULL DEFAULT '',
  `payload_json` longtext DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `state_key` varchar(100) DEFAULT NULL,
  `state_data` text DEFAULT NULL,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `expires_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

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

CREATE TABLE `broadcast_logs` (
  `id` int(10) UNSIGNED NOT NULL,
  `admin_id` bigint(20) NOT NULL,
  `message` text DEFAULT NULL,
  `target_type` varchar(50) DEFAULT 'all',
  `total_users` int(11) NOT NULL DEFAULT 0,
  `sent_count` int(11) NOT NULL DEFAULT 0,
  `failed_count` int(11) NOT NULL DEFAULT 0,
  `blocked_count` int(11) NOT NULL DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `credentials`
--

CREATE TABLE `credentials` (
  `id` int(10) UNSIGNED NOT NULL,
  `category_id` int(10) UNSIGNED DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL COMMENT 'VPN username - legacy field name',
  `username` varchar(128) DEFAULT NULL COMMENT 'VPN username mirror',
  `password` varchar(255) NOT NULL,
  `config_text` mediumtext DEFAULT NULL,
  `qr_code_file_id` varchar(255) DEFAULT NULL,
  `qr_code_path` varchar(500) DEFAULT NULL,
  `duration` varchar(20) NOT NULL DEFAULT '1M',
  `months` int(11) NOT NULL DEFAULT 1,
  `max_seats` int(11) NOT NULL DEFAULT 1,
  `traffic_type` varchar(20) NOT NULL DEFAULT 'unlimited',
  `traffic_limit_gb` int(10) UNSIGNED DEFAULT NULL,
  `used_seats` int(11) NOT NULL DEFAULT 0,
  `assigned_user_id` bigint(20) DEFAULT NULL,
  `assigned_order_id` int(10) UNSIGNED DEFAULT NULL,
  `first_connected_at` timestamp NULL DEFAULT NULL,
  `first_connection_at` datetime DEFAULT NULL,
  `expires_at` datetime DEFAULT NULL,
  `plan_id` int(10) UNSIGNED DEFAULT NULL,
  `protocol` varchar(30) NOT NULL DEFAULT 'openvpn_l2tp',
  `sellable_until` datetime DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `sales_paused` tinyint(1) NOT NULL DEFAULT 0,
  `is_sold` tinyint(1) NOT NULL DEFAULT 0,
  `status` varchar(30) NOT NULL DEFAULT 'available',
  `sold_to_user_id` bigint(20) DEFAULT NULL,
  `order_id` bigint(20) DEFAULT NULL,
  `sold_at` datetime DEFAULT NULL,
  `delivered_at` datetime DEFAULT NULL,
  `disabled_at` datetime DEFAULT NULL,
  `deleted_at` datetime DEFAULT NULL,
  `warning_5d_sent` tinyint(1) NOT NULL DEFAULT 0,
  `capacity_warn_sent` tinyint(1) NOT NULL DEFAULT 0,
  `created_by` bigint(20) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `archived_at` datetime DEFAULT NULL,
  `archived_by` bigint(20) DEFAULT NULL,
  `archive_reason` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `crypto_payments`
--

CREATE TABLE `crypto_payments` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `order_id` int(10) UNSIGNED DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `wallet_transaction_id` int(10) UNSIGNED DEFAULT NULL,
  `amount` decimal(18,2) NOT NULL DEFAULT 0.00,
  `currency` varchar(20) NOT NULL DEFAULT 'IRT',
  `crypto_currency` varchar(20) DEFAULT NULL,
  `network` varchar(30) DEFAULT NULL,
  `wallet_address` varchar(255) DEFAULT NULL,
  `payment_type` varchar(30) NOT NULL DEFAULT 'order',
  `provider` varchar(50) NOT NULL DEFAULT 'SwapWallet',
  `provider_invoice_id` varchar(255) DEFAULT NULL,
  `provider_order_id` varchar(255) DEFAULT NULL,
  `payment_url` text DEFAULT NULL,
  `receipt_file_id` varchar(255) DEFAULT NULL,
  `receipt_text` text DEFAULT NULL,
  `processed_by` bigint(20) DEFAULT NULL,
  `processed_at` datetime DEFAULT NULL,
  `status` varchar(30) DEFAULT 'PENDING',
  `raw_request` longtext DEFAULT NULL,
  `raw_response` longtext DEFAULT NULL,
  `paid_at` datetime DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `deliveries`
--

CREATE TABLE `deliveries` (
  `id` int(10) UNSIGNED NOT NULL,
  `order_id` int(10) UNSIGNED NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `credential_id` int(10) UNSIGNED DEFAULT NULL,
  `vpn_account_id` bigint(20) UNSIGNED DEFAULT NULL,
  `username` varchar(128) DEFAULT NULL,
  `password` varchar(255) DEFAULT NULL,
  `config_text` mediumtext DEFAULT NULL,
  `qr_code_file_id` varchar(255) DEFAULT NULL,
  `qr_code_path` varchar(500) DEFAULT NULL,
  `service_type` varchar(30) NOT NULL DEFAULT 'openvpn_l2tp',
  `traffic_type` varchar(20) NOT NULL DEFAULT 'unlimited',
  `traffic_limit_gb` int(10) UNSIGNED DEFAULT NULL,
  `seats_allocated` int(11) NOT NULL DEFAULT 1,
  `status` varchar(30) NOT NULL DEFAULT 'delivered',
  `notification_status` varchar(20) NOT NULL DEFAULT 'pending',
  `notification_sent_at` timestamp NULL DEFAULT NULL,
  `notification_error` text DEFAULT NULL,
  `notification_attempts` int(11) NOT NULL DEFAULT 0,
  `delivered_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `discount_codes`
--

CREATE TABLE `discount_codes` (
  `id` int(10) UNSIGNED NOT NULL,
  `code` varchar(50) NOT NULL,
  `type` varchar(30) NOT NULL DEFAULT 'PERCENT',
  `value` int(11) NOT NULL DEFAULT 0,
  `min_purchase` int(11) NOT NULL DEFAULT 0,
  `max_discount` int(11) DEFAULT NULL,
  `max_uses` int(11) DEFAULT NULL,
  `max_uses_per_user` int(11) NOT NULL DEFAULT 1,
  `used_count` int(11) NOT NULL DEFAULT 0,
  `valid_from` timestamp NULL DEFAULT NULL,
  `valid_until` timestamp NULL DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `payment_scope` varchar(20) NOT NULL DEFAULT 'all',
  `created_by` bigint(20) DEFAULT NULL,
  `broadcast_target` varchar(30) DEFAULT NULL,
  `broadcast_message` text DEFAULT NULL,
  `broadcast_file_id` varchar(255) DEFAULT NULL,
  `broadcast_file_type` varchar(30) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `discount_usages`
--

CREATE TABLE `discount_usages` (
  `id` int(10) UNSIGNED NOT NULL,
  `discount_id` int(10) UNSIGNED NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `order_id` int(10) UNSIGNED DEFAULT NULL,
  `discount_amount` int(11) NOT NULL,
  `used_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `fake_receipt_warnings`
--

CREATE TABLE `fake_receipt_warnings` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `order_id` bigint(20) NOT NULL,
  `admin_id` bigint(20) DEFAULT NULL,
  `warning_number` int(11) NOT NULL DEFAULT 1,
  `user_blocked` tinyint(1) NOT NULL DEFAULT 0,
  `message_sent` tinyint(1) NOT NULL DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `faq_items`
--

CREATE TABLE `faq_items` (
  `id` int(10) UNSIGNED NOT NULL,
  `question` varchar(255) NOT NULL,
  `answer` mediumtext NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `display_order` int(11) NOT NULL DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `first_connections`
--

CREATE TABLE `first_connections` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `credential_id` int(10) UNSIGNED DEFAULT NULL,
  `vpn_account_id` bigint(20) UNSIGNED DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `order_id` int(10) UNSIGNED DEFAULT NULL,
  `username` varchar(255) NOT NULL,
  `first_connected_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `first_connection_at` datetime DEFAULT NULL,
  `expires_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `forced_channels`
--

CREATE TABLE `forced_channels` (
  `id` int(10) UNSIGNED NOT NULL,
  `channel_username` varchar(255) NOT NULL,
  `channel_title` varchar(255) DEFAULT NULL,
  `invite_link` text DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `jobs`
--

CREATE TABLE `jobs` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `type` varchar(100) NOT NULL,
  `payload` mediumtext NOT NULL,
  `status` varchar(30) NOT NULL DEFAULT 'PENDING',
  `attempts` int(11) NOT NULL DEFAULT 0,
  `max_attempts` int(11) NOT NULL DEFAULT 5,
  `last_error` text DEFAULT NULL,
  `dedupe_key` varchar(191) DEFAULT NULL,
  `available_at` datetime NOT NULL DEFAULT current_timestamp(),
  `reserved_at` datetime DEFAULT NULL,
  `done_at` datetime DEFAULT NULL,
  `failed_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` int(10) UNSIGNED NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `plan_id` int(10) UNSIGNED DEFAULT NULL,
  `category_id` int(10) UNSIGNED DEFAULT NULL,
  `plan_code` varchar(50) DEFAULT NULL,
  `plan_title` varchar(255) DEFAULT NULL,
  `service_type` varchar(30) NOT NULL DEFAULT 'openvpn_l2tp',
  `duration` varchar(20) NOT NULL DEFAULT '1M',
  `months` int(11) NOT NULL DEFAULT 1,
  `requested_seats` int(11) NOT NULL DEFAULT 1,
  `traffic_type` varchar(20) NOT NULL DEFAULT 'unlimited',
  `traffic_limit_gb` int(10) UNSIGNED DEFAULT NULL,
  `required_accounts` int(11) NOT NULL DEFAULT 1,
  `delivered_accounts` int(11) NOT NULL DEFAULT 0,
  `price` int(11) NOT NULL DEFAULT 0,
  `purchase_price` int(11) NOT NULL DEFAULT 0,
  `payment_method` varchar(30) NOT NULL DEFAULT 'CARD',
  `payment_status` varchar(30) NOT NULL DEFAULT 'pending',
  `crypto_payment_id` bigint(20) UNSIGNED DEFAULT NULL,
  `delivery_status` varchar(30) NOT NULL DEFAULT 'pending',
  `status` varchar(30) NOT NULL DEFAULT 'PENDING',
  `receipt_file_id` varchar(255) DEFAULT NULL,
  `receipt_text` text DEFAULT NULL,
  `stars_expires_at` datetime DEFAULT NULL,
  `stars_auto_cancel_notified_at` datetime DEFAULT NULL,
  `activated_at` datetime DEFAULT NULL,
  `first_connection_at` datetime DEFAULT NULL,
  `expires_at` datetime DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `approved_at` timestamp NULL DEFAULT NULL,
  `rejected_at` timestamp NULL DEFAULT NULL,
  `delivered_at` timestamp NULL DEFAULT NULL,
  `reminder_29d_sent` tinyint(1) NOT NULL DEFAULT 0,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `fake_receipt_warning_at` datetime DEFAULT NULL,
  `fake_receipt_warning_by` bigint(20) DEFAULT NULL,
  `fake_receipt_warning_no` int(11) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `payment_idempotency`
--

CREATE TABLE `payment_idempotency` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `request_id` varchar(128) NOT NULL,
  `scope` varchar(40) NOT NULL,
  `order_id` int(10) UNSIGNED DEFAULT NULL,
  `status` varchar(30) NOT NULL DEFAULT 'processing',
  `response_json` longtext DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `pending_deliveries`
--

CREATE TABLE `pending_deliveries` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `order_id` int(10) UNSIGNED NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `plan_id` int(10) UNSIGNED DEFAULT NULL,
  `category_id` int(10) UNSIGNED DEFAULT NULL,
  `required_accounts` int(11) NOT NULL DEFAULT 1,
  `delivered_accounts` int(11) NOT NULL DEFAULT 0,
  `status` varchar(30) NOT NULL DEFAULT 'pending',
  `last_error` text 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 `plans`
--

CREATE TABLE `plans` (
  `id` int(10) UNSIGNED NOT NULL,
  `category_id` int(10) UNSIGNED DEFAULT NULL,
  `code` varchar(50) NOT NULL,
  `title` varchar(255) NOT NULL,
  `duration` varchar(20) NOT NULL DEFAULT '1M',
  `months` int(11) NOT NULL DEFAULT 1,
  `seats` int(11) NOT NULL DEFAULT 1,
  `user_count` int(11) NOT NULL DEFAULT 1,
  `protocol` varchar(30) NOT NULL DEFAULT 'openvpn_l2tp',
  `service_name` varchar(100) DEFAULT NULL,
  `traffic_type` varchar(20) NOT NULL DEFAULT 'unlimited',
  `traffic_limit_gb` int(10) UNSIGNED DEFAULT NULL,
  `price` int(11) NOT NULL DEFAULT 0,
  `purchase_price` int(11) NOT NULL DEFAULT 0,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `display_order` int(11) NOT NULL DEFAULT 0,
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `deleted_at` datetime DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `plan_categories`
--

CREATE TABLE `plan_categories` (
  `id` int(10) UNSIGNED NOT NULL,
  `code` varchar(20) NOT NULL,
  `service_type` varchar(30) NOT NULL DEFAULT 'openvpn_l2tp',
  `service_name` varchar(100) DEFAULT NULL,
  `name` varchar(100) NOT NULL,
  `months` int(11) NOT NULL DEFAULT 1,
  `traffic_type` varchar(20) NOT NULL DEFAULT 'unlimited',
  `traffic_limit_gb` int(10) UNSIGNED DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `display_order` int(11) NOT NULL DEFAULT 0,
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `deleted_at` datetime DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `rate_limits`
--

CREATE TABLE `rate_limits` (
  `bucket` varchar(100) NOT NULL,
  `ts_minute` int(11) NOT NULL,
  `count` int(11) NOT NULL DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `referral_events`
--

CREATE TABLE `referral_events` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `referrer_id` bigint(20) DEFAULT NULL,
  `event_type` varchar(50) NOT NULL,
  `meta_json` longtext DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `referral_rewards`
--

CREATE TABLE `referral_rewards` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `referrer_id` bigint(20) NOT NULL,
  `referred_user_id` bigint(20) NOT NULL,
  `order_id` bigint(20) UNSIGNED NOT NULL,
  `amount` int(11) NOT NULL DEFAULT 0,
  `status` varchar(30) NOT NULL DEFAULT 'COMPLETED',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

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

CREATE TABLE `resellers` (
  `user_id` bigint(20) NOT NULL,
  `discount_percent` decimal(5,2) NOT NULL DEFAULT 0.00,
  `fixed_discount` int(11) NOT NULL DEFAULT 0,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `notes` text DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `sales`
--

CREATE TABLE `sales` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `order_id` int(10) UNSIGNED DEFAULT NULL,
  `user_id` bigint(20) NOT NULL,
  `plan_id` int(10) UNSIGNED DEFAULT NULL,
  `plan_title` varchar(255) DEFAULT NULL,
  `username` varchar(128) DEFAULT NULL,
  `password` varchar(255) DEFAULT NULL,
  `duration` varchar(20) DEFAULT NULL,
  `months` int(11) NOT NULL DEFAULT 1,
  `traffic_type` varchar(20) NOT NULL DEFAULT 'unlimited',
  `traffic_limit_gb` int(10) UNSIGNED DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `first_connection_at` datetime DEFAULT NULL,
  `expires_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 `schema_migrations`
--

CREATE TABLE `schema_migrations` (
  `id` int(11) NOT NULL,
  `migration` varchar(191) NOT NULL,
  `applied_at` timestamp NULL DEFAULT current_timestamp(),
  `version` varchar(191) DEFAULT NULL,
  `name` varchar(190) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `service_expiry_reminders`
--

CREATE TABLE `service_expiry_reminders` (
  `id` int(10) UNSIGNED NOT NULL,
  `sale_id` bigint(20) UNSIGNED NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `reminder_type` varchar(30) NOT NULL,
  `sent_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `settings`
--

CREATE TABLE `settings` (
  `key_name` varchar(100) NOT NULL,
  `value` text DEFAULT NULL,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;



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

--
-- Table structure for Android SMS payment auto-approval
--

CREATE TABLE `sms_payment_events` (
  `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `sms_hash` char(64) NOT NULL,
  `sender` varchar(120) DEFAULT NULL,
  `body_text` mediumtext NOT NULL,
  `amount_rial` bigint(20) DEFAULT NULL,
  `received_at` datetime DEFAULT NULL,
  `uploaded_at` datetime NOT NULL DEFAULT current_timestamp(),
  `status` varchar(30) NOT NULL DEFAULT 'received',
  `matched_order_id` bigint(20) UNSIGNED DEFAULT NULL,
  `match_count` int(11) NOT NULL DEFAULT 0,
  `error_text` text DEFAULT NULL,
  `raw_json` longtext DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_sms_hash` (`sms_hash`),
  KEY `idx_amount_received` (`amount_rial`,`received_at`),
  KEY `idx_status_uploaded` (`status`,`uploaded_at`),
  KEY `idx_matched_order` (`matched_order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `sms_payment_matches` (
  `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `event_id` bigint(20) UNSIGNED NOT NULL,
  `order_id` bigint(20) UNSIGNED NOT NULL,
  `amount_rial` bigint(20) NOT NULL,
  `match_status` varchar(30) NOT NULL DEFAULT 'matched',
  `approved_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `note` text DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_event_order` (`event_id`,`order_id`),
  UNIQUE KEY `uq_order_once` (`order_id`),
  KEY `idx_event` (`event_id`),
  KEY `idx_status` (`match_status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `support_messages`
--

CREATE TABLE `support_messages` (
  `id` int(10) UNSIGNED NOT NULL,
  `ticket_id` int(10) UNSIGNED NOT NULL,
  `sender_id` bigint(20) NOT NULL,
  `sender_role` varchar(30) NOT NULL DEFAULT 'USER',
  `message_text` mediumtext NOT NULL,
  `telegram_file_id` varchar(255) DEFAULT NULL,
  `attachment_type` varchar(30) DEFAULT NULL,
  `attachment_name` varchar(255) DEFAULT NULL,
  `attachment_mime` varchar(160) DEFAULT NULL,
  `attachment_path` varchar(500) DEFAULT NULL,
  `is_admin_reply` tinyint(1) NOT NULL DEFAULT 0,
  `is_read` tinyint(1) NOT NULL DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `sent_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `support_tickets`
--

CREATE TABLE `support_tickets` (
  `id` int(10) UNSIGNED NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `subject` varchar(255) DEFAULT 'درخواست پشتیبانی',
  `status` varchar(30) NOT NULL DEFAULT 'OPEN',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `priority` varchar(20) NOT NULL DEFAULT 'normal',
  `category` varchar(60) NOT NULL DEFAULT 'support',
  `assigned_admin_id` bigint(20) DEFAULT NULL,
  `unread_admin_count` int(11) NOT NULL DEFAULT 0,
  `unread_user_count` int(11) NOT NULL DEFAULT 0,
  `last_message_at` datetime DEFAULT NULL,
  `closed_at` datetime DEFAULT NULL,
  `closed_by` bigint(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `telegram_update_queue`
--

CREATE TABLE `telegram_update_queue` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `update_id` bigint(20) DEFAULT NULL,
  `update_type` varchar(50) NOT NULL DEFAULT 'unknown',
  `payload_json` longtext NOT NULL,
  `payload_hash` char(64) NOT NULL,
  `status` varchar(30) NOT NULL DEFAULT 'PENDING',
  `attempts` int(11) NOT NULL DEFAULT 0,
  `max_attempts` int(11) NOT NULL DEFAULT 5,
  `last_error` text DEFAULT NULL,
  `received_at` datetime NOT NULL DEFAULT current_timestamp(),
  `reserved_at` datetime DEFAULT NULL,
  `processed_at` datetime DEFAULT NULL,
  `failed_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

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

CREATE TABLE `tutorials` (
  `id` int(10) UNSIGNED NOT NULL,
  `service_type` varchar(30) NOT NULL DEFAULT 'openvpn_l2tp',
  `device` varchar(30) NOT NULL,
  `text_content` mediumtext DEFAULT NULL,
  `video_file_id` varchar(255) DEFAULT NULL,
  `media_file_id` varchar(255) DEFAULT NULL,
  `media_type` varchar(30) DEFAULT NULL,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `id` bigint(20) NOT NULL COMMENT 'Telegram user id',
  `username` varchar(100) DEFAULT NULL,
  `first_name` varchar(255) DEFAULT NULL,
  `last_name` varchar(255) DEFAULT NULL,
  `is_admin` tinyint(1) NOT NULL DEFAULT 0,
  `balance` int(11) NOT NULL DEFAULT 0,
  `is_blocked` tinyint(1) NOT NULL DEFAULT 0,
  `blocked_reason` text DEFAULT NULL,
  `blocked_at` datetime DEFAULT NULL,
  `total_purchases` int(11) NOT NULL DEFAULT 0,
  `total_cashback` int(11) NOT NULL DEFAULT 0,
  `has_wallet_bonus` tinyint(1) NOT NULL DEFAULT 0,
  `referrer_id` bigint(20) DEFAULT NULL,
  `state` varchar(100) DEFAULT NULL,
  `state_data` text DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `fake_receipt_warnings` int(11) NOT NULL DEFAULT 0,
  `last_fake_receipt_warning_at` datetime DEFAULT NULL,
  `last_referral_reward_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `user_avatars`
--

CREATE TABLE `user_avatars` (
  `user_id` bigint(20) NOT NULL,
  `current_avatar` int(11) NOT NULL DEFAULT 1,
  `unlocked_avatars` varchar(100) DEFAULT '1',
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

--
-- Table structure for table `user_discount_codes`
--

CREATE TABLE `user_discount_codes` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `discount_id` int(10) UNSIGNED DEFAULT NULL,
  `code` varchar(50) NOT NULL,
  `title` varchar(255) DEFAULT NULL,
  `message` text DEFAULT NULL,
  `source` varchar(50) DEFAULT 'admin',
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `used_at` datetime DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `vpn_accounts`
--

CREATE TABLE `vpn_accounts` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `username` varchar(128) NOT NULL,
  `password` varchar(255) NOT NULL,
  `protocol` varchar(30) NOT NULL DEFAULT 'openvpn_l2tp',
  `category_id` int(10) UNSIGNED DEFAULT NULL,
  `plan_id` int(10) UNSIGNED DEFAULT NULL,
  `months` int(11) NOT NULL DEFAULT 1,
  `traffic_type` varchar(20) NOT NULL DEFAULT 'unlimited',
  `traffic_limit_gb` int(10) UNSIGNED DEFAULT NULL,
  `status` varchar(30) NOT NULL DEFAULT 'available',
  `is_sold` tinyint(1) NOT NULL DEFAULT 0,
  `sold_to_user_id` bigint(20) DEFAULT NULL,
  `order_id` bigint(20) DEFAULT NULL,
  `first_connection_at` datetime DEFAULT NULL,
  `expires_at` datetime DEFAULT NULL,
  `sold_at` datetime DEFAULT NULL,
  `delivered_at` datetime DEFAULT NULL,
  `disabled_at` datetime DEFAULT NULL,
  `meta` text 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 `vpn_connections`
--

CREATE TABLE `vpn_connections` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `credential_id` int(10) UNSIGNED DEFAULT NULL,
  `vpn_account_id` bigint(20) UNSIGNED DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `username` varchar(255) NOT NULL,
  `connected_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `source_ip` varchar(64) DEFAULT NULL,
  `ip_address` varchar(64) DEFAULT NULL,
  `device_info` varchar(255) DEFAULT NULL,
  `raw_payload` longtext DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Stand-in structure for view `vw_active_plan_categories`
-- (See below for the actual view)
--
CREATE TABLE `vw_active_plan_categories` (
`id` int(10) unsigned
,`code` varchar(20)
,`service_type` varchar(30)
,`name` varchar(100)
,`months` int(11)
,`traffic_type` varchar(20)
,`traffic_limit_gb` int(10) unsigned
,`is_active` tinyint(1)
,`display_order` int(11)
,`sort_order` int(11)
,`deleted_at` datetime
,`created_at` timestamp
,`updated_at` timestamp
);

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

--
-- Stand-in structure for view `vw_available_credentials`
-- (See below for the actual view)
--
CREATE TABLE `vw_available_credentials` (
`id` int(10) unsigned
,`category_id` int(10) unsigned
,`email` varchar(255)
,`username` varchar(128)
,`password` varchar(255)
,`duration` varchar(20)
,`months` int(11)
,`max_seats` int(11)
,`traffic_type` varchar(20)
,`traffic_limit_gb` int(10) unsigned
,`used_seats` int(11)
,`assigned_user_id` bigint(20)
,`assigned_order_id` int(10) unsigned
,`first_connected_at` timestamp
,`first_connection_at` datetime
,`expires_at` datetime
,`plan_id` int(10) unsigned
,`protocol` varchar(30)
,`sellable_until` datetime
,`is_active` tinyint(1)
,`sales_paused` tinyint(1)
,`is_sold` tinyint(1)
,`status` varchar(30)
,`sold_to_user_id` bigint(20)
,`order_id` bigint(20)
,`sold_at` datetime
,`delivered_at` datetime
,`disabled_at` datetime
,`deleted_at` datetime
,`warning_5d_sent` tinyint(1)
,`capacity_warn_sent` tinyint(1)
,`created_by` bigint(20)
,`created_at` timestamp
,`updated_at` timestamp
);

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

--
-- Stand-in structure for view `vw_user_services`
-- (See below for the actual view)
--
CREATE TABLE `vw_user_services` (
`delivery_id` int(10) unsigned
,`order_id` int(10) unsigned
,`user_id` bigint(20)
,`credential_id` int(10) unsigned
,`vpn_account_id` bigint(20) unsigned
,`username` varchar(255)
,`password` varchar(255)
,`first_connection_at` datetime /* mariadb-5.3 */
,`expires_at` datetime /* mariadb-5.3 */
,`delivered_at` timestamp
,`status` varchar(30)
);

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

--
-- Table structure for table `waiting_queue`
--

CREATE TABLE `waiting_queue` (
  `id` int(10) UNSIGNED NOT NULL,
  `order_id` int(10) UNSIGNED NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `plan_id` int(10) UNSIGNED DEFAULT NULL,
  `category_id` int(10) UNSIGNED DEFAULT NULL,
  `duration` varchar(20) NOT NULL DEFAULT '1M',
  `service_type` varchar(30) NOT NULL DEFAULT 'openvpn_l2tp',
  `requested_seats` int(11) NOT NULL DEFAULT 1,
  `traffic_type` varchar(20) NOT NULL DEFAULT 'unlimited',
  `traffic_limit_gb` int(10) UNSIGNED DEFAULT NULL,
  `required_accounts` int(11) NOT NULL DEFAULT 1,
  `processed_at` timestamp NULL DEFAULT NULL,
  `status` varchar(30) NOT NULL DEFAULT 'pending',
  `reason` varchar(255) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


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

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

CREATE TABLE `wallet_transactions` (
  `id` int(10) UNSIGNED NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `amount` int(11) NOT NULL,
  `type` varchar(30) NOT NULL,
  `status` varchar(30) NOT NULL DEFAULT 'PENDING',
  `payment_method` varchar(30) DEFAULT 'card',
  `crypto_payment_id` bigint(20) UNSIGNED DEFAULT NULL,
  `currency` varchar(20) NOT NULL DEFAULT 'IRT',
  `description` text DEFAULT NULL,
  `receipt_file_id` varchar(255) DEFAULT NULL,
  `receipt_text` text DEFAULT NULL,
  `processed_by` bigint(20) DEFAULT NULL,
  `processed_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


--
-- Indexes for dumped tables
--

--
-- Indexes for table `admin_chat_notes`
--
ALTER TABLE `admin_chat_notes`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_user_created` (`user_id`,`created_at`),
  ADD KEY `idx_admin_created` (`admin_id`,`created_at`);

--
-- Indexes for table `admin_logs`
--
ALTER TABLE `admin_logs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_admin_logs_admin` (`admin_user_id`),
  ADD KEY `idx_admin_logs_action` (`action`),
  ADD KEY `idx_admin_logs_target` (`target_type`,`target_id`),
  ADD KEY `idx_admin_logs_created` (`created_at`);

--
-- Indexes for table `admin_private_messages`
--
ALTER TABLE `admin_private_messages`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_user_created` (`user_id`,`created_at`),
  ADD KEY `idx_admin_created` (`admin_id`,`created_at`),
  ADD KEY `idx_direction_created` (`direction`,`created_at`);

--
-- Indexes for table `app_migrations`
--
ALTER TABLE `app_migrations`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `version` (`version`);

--
-- Indexes for table `bot_user_states`
--
ALTER TABLE `bot_user_states`
  ADD PRIMARY KEY (`user_id`),
  ADD KEY `idx_bot_user_states_state` (`state_key`);

--
-- Indexes for table `broadcast_logs`
--
ALTER TABLE `broadcast_logs`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `credentials`
--
ALTER TABLE `credentials`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_credentials_email` (`email`),
  ADD KEY `idx_credentials_username` (`username`),
  ADD KEY `idx_credentials_duration` (`duration`),
  ADD KEY `idx_credentials_traffic` (`traffic_type`,`traffic_limit_gb`),
  ADD KEY `idx_credentials_active` (`is_active`),
  ADD KEY `idx_credentials_sellable` (`sellable_until`),
  ADD KEY `idx_credentials_fifo` (`duration`,`is_active`,`used_seats`,`created_at`),
  ADD KEY `idx_credentials_available` (`is_sold`,`status`,`is_active`),
  ADD KEY `idx_credentials_category` (`category_id`),
  ADD KEY `idx_credentials_plan` (`plan_id`),
  ADD KEY `idx_credentials_assigned_user` (`assigned_user_id`),
  ADD KEY `idx_credentials_assigned_order` (`assigned_order_id`),
  ADD KEY `idx_credentials_order` (`order_id`),
  ADD KEY `idx_credentials_protocol_capacity` (`protocol`,`duration`,`is_active`,`used_seats`),
  ADD KEY `idx_credentials_deleted` (`deleted_at`),
  ADD KEY `idx_cred_available` (`duration`,`is_active`,`used_seats`,`created_at`),
  ADD KEY `idx_credentials_admin_inventory` (`is_active`,`status`,`sales_paused`,`used_seats`,`max_seats`),
  ADD KEY `idx_credentials_archived_at` (`archived_at`);

--
-- Indexes for table `crypto_payments`
--
ALTER TABLE `crypto_payments`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_crypto_order` (`order_id`),
  ADD KEY `idx_crypto_user_status` (`user_id`,`status`),
  ADD KEY `idx_crypto_wallet_tx` (`wallet_transaction_id`),
  ADD KEY `idx_crypto_invoice` (`provider_invoice_id`(191)),
  ADD KEY `idx_crypto_provider_order` (`provider_order_id`(191)),
  ADD KEY `idx_crypto_type` (`payment_type`);

--
-- Indexes for table `deliveries`
--
ALTER TABLE `deliveries`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_deliveries_order` (`order_id`),
  ADD KEY `idx_deliveries_user` (`user_id`),
  ADD KEY `idx_deliveries_credential` (`credential_id`),
  ADD KEY `idx_deliveries_vpn_account` (`vpn_account_id`),
  ADD KEY `idx_deliveries_status_delivered` (`status`,`delivered_at`),
  ADD KEY `idx_deliveries_search_user_order` (`user_id`,`order_id`),
  ADD KEY `idx_deliveries_notification_status` (`notification_status`);

--
-- Indexes for table `discount_codes`
--
ALTER TABLE `discount_codes`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `code` (`code`),
  ADD KEY `idx_discount_active` (`is_active`);

--
-- Indexes for table `discount_usages`
--
ALTER TABLE `discount_usages`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_discount_user_order` (`discount_id`,`user_id`,`order_id`),
  ADD KEY `idx_discount_usages_discount` (`discount_id`),
  ADD KEY `idx_discount_usages_user` (`user_id`);

--
-- Indexes for table `fake_receipt_warnings`
--
ALTER TABLE `fake_receipt_warnings`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_user_created` (`user_id`,`created_at`),
  ADD KEY `idx_order` (`order_id`),
  ADD KEY `idx_admin` (`admin_id`);

--
-- Indexes for table `faq_items`
--
ALTER TABLE `faq_items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_faq_active_order` (`is_active`,`display_order`,`id`);

--
-- Indexes for table `first_connections`
--
ALTER TABLE `first_connections`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_first_connections_credential` (`credential_id`),
  ADD KEY `idx_first_connections_username` (`username`),
  ADD KEY `idx_first_connections_user` (`user_id`),
  ADD KEY `idx_first_connections_order` (`order_id`),
  ADD KEY `idx_first_connections_vpn_account` (`vpn_account_id`);

--
-- Indexes for table `forced_channels`
--
ALTER TABLE `forced_channels`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `channel_username` (`channel_username`),
  ADD KEY `idx_forced_channel_active` (`is_active`);

--
-- Indexes for table `jobs`
--
ALTER TABLE `jobs`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_jobs_dedupe` (`dedupe_key`),
  ADD KEY `idx_jobs_status_available` (`status`,`available_at`),
  ADD KEY `idx_jobs_type` (`type`);

--
-- Indexes for table `orders`
--
ALTER TABLE `orders`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_orders_user` (`user_id`),
  ADD KEY `idx_orders_plan` (`plan_id`),
  ADD KEY `idx_orders_category` (`category_id`),
  ADD KEY `idx_orders_status` (`status`),
  ADD KEY `idx_orders_delivery_status` (`delivery_status`),
  ADD KEY `idx_orders_payment_status` (`payment_status`),
  ADD KEY `idx_orders_created` (`created_at`),
  ADD KEY `idx_orders_duration` (`duration`),
  ADD KEY `idx_orders_traffic` (`traffic_type`,`traffic_limit_gb`),
  ADD KEY `idx_orders_stars_pending_expire` (`payment_method`,`payment_status`,`status`,`stars_expires_at`);

--
-- Indexes for table `payment_idempotency`
--
ALTER TABLE `payment_idempotency`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_payment_request` (`user_id`,`request_id`,`scope`),
  ADD KEY `idx_payment_order` (`order_id`);

--
-- Indexes for table `pending_deliveries`
--
ALTER TABLE `pending_deliveries`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_pending_deliveries_order` (`order_id`),
  ADD KEY `idx_pending_deliveries_status` (`status`),
  ADD KEY `idx_pending_deliveries_user` (`user_id`),
  ADD KEY `idx_pending_deliveries_plan` (`plan_id`),
  ADD KEY `idx_pending_deliveries_category` (`category_id`);

--
-- Indexes for table `plans`
--
ALTER TABLE `plans`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `code` (`code`),
  ADD KEY `idx_plans_category` (`category_id`),
  ADD KEY `idx_plans_duration` (`duration`),
  ADD KEY `idx_plans_months` (`months`),
  ADD KEY `idx_plans_traffic` (`traffic_type`,`traffic_limit_gb`),
  ADD KEY `idx_plans_active` (`is_active`),
  ADD KEY `idx_plans_deleted` (`deleted_at`),
  ADD KEY `idx_plans_order` (`display_order`);

--
-- Indexes for table `plan_categories`
--
ALTER TABLE `plan_categories`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `code` (`code`),
  ADD KEY `idx_plan_categories_active_order` (`is_active`,`display_order`),
  ADD KEY `idx_plan_categories_months` (`months`),
  ADD KEY `idx_plan_categories_traffic` (`traffic_type`,`traffic_limit_gb`),
  ADD KEY `idx_plan_categories_deleted` (`deleted_at`);

--
-- Indexes for table `rate_limits`
--
ALTER TABLE `rate_limits`
  ADD PRIMARY KEY (`bucket`,`ts_minute`),
  ADD KEY `idx_rate_limits_ts` (`ts_minute`);

--
-- Indexes for table `referral_events`
--
ALTER TABLE `referral_events`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_user_created` (`user_id`,`created_at`),
  ADD KEY `idx_referrer_created` (`referrer_id`,`created_at`);

--
-- Indexes for table `referral_rewards`
--
ALTER TABLE `referral_rewards`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_referred_first_order` (`referred_user_id`),
  ADD KEY `idx_referrer_created` (`referrer_id`,`created_at`),
  ADD KEY `idx_order` (`order_id`);

--
-- Indexes for table `resellers`
--
ALTER TABLE `resellers`
  ADD PRIMARY KEY (`user_id`),
  ADD KEY `idx_resellers_active` (`is_active`);

--
-- Indexes for table `sales`
--
ALTER TABLE `sales`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_sales_user` (`user_id`),
  ADD KEY `idx_sales_order` (`order_id`),
  ADD KEY `idx_sales_plan` (`plan_id`),
  ADD KEY `idx_sales_active` (`is_active`),
  ADD KEY `idx_sales_expires` (`expires_at`);

--
-- Indexes for table `schema_migrations`
--
ALTER TABLE `schema_migrations`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `migration` (`migration`),
  ADD UNIQUE KEY `uniq_schema_migrations_version` (`version`);

--
-- Indexes for table `service_expiry_reminders`
--
ALTER TABLE `service_expiry_reminders`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `unique_reminder` (`sale_id`,`reminder_type`),
  ADD KEY `idx_service_expiry_sale` (`sale_id`),
  ADD KEY `idx_service_expiry_user` (`user_id`);

--
-- Indexes for table `settings`
--
ALTER TABLE `settings`
  ADD PRIMARY KEY (`key_name`);

--
-- Indexes for table `support_messages`
--
ALTER TABLE `support_messages`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_support_messages_ticket` (`ticket_id`),
  ADD KEY `idx_support_messages_sender` (`sender_id`),
  ADD KEY `idx_support_messages_admin_unread` (`is_admin_reply`,`is_read`);

--
-- Indexes for table `support_tickets`
--
ALTER TABLE `support_tickets`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_support_tickets_user` (`user_id`),
  ADD KEY `idx_support_tickets_status` (`status`);

--
-- Indexes for table `telegram_update_queue`
--
ALTER TABLE `telegram_update_queue`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tg_payload_hash` (`payload_hash`),
  ADD UNIQUE KEY `uniq_tg_update_id` (`update_id`),
  ADD KEY `idx_tg_status_received` (`status`,`received_at`),
  ADD KEY `idx_tg_type` (`update_type`);

--
-- Indexes for table `tutorials`
--
ALTER TABLE `tutorials`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tutorial_service_device` (`service_type`,`device`),
  ADD KEY `idx_tutorials_service` (`service_type`),
  ADD KEY `idx_tutorials_media_type` (`media_type`);

--
-- Indexes for table `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_users_username` (`username`),
  ADD KEY `idx_users_created_at` (`created_at`),
  ADD KEY `idx_users_state` (`state`);

--
-- Indexes for table `user_avatars`
--
ALTER TABLE `user_avatars`
  ADD PRIMARY KEY (`user_id`);

--
-- Indexes for table `user_discount_codes`
--
ALTER TABLE `user_discount_codes`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_user_code` (`user_id`,`code`),
  ADD KEY `idx_udc_user` (`user_id`);

--
-- Indexes for table `vpn_accounts`
--
ALTER TABLE `vpn_accounts`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_vpn_accounts_username` (`username`),
  ADD KEY `idx_vpn_accounts_status` (`status`),
  ADD KEY `idx_vpn_accounts_sold` (`is_sold`),
  ADD KEY `idx_vpn_accounts_category` (`category_id`),
  ADD KEY `idx_vpn_accounts_plan` (`plan_id`),
  ADD KEY `idx_vpn_accounts_user` (`sold_to_user_id`),
  ADD KEY `idx_vpn_accounts_order` (`order_id`);

--
-- Indexes for table `vpn_connections`
--
ALTER TABLE `vpn_connections`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_vpn_connections_username` (`username`),
  ADD KEY `idx_vpn_connections_credential` (`credential_id`),
  ADD KEY `idx_vpn_connections_account` (`vpn_account_id`),
  ADD KEY `idx_vpn_connections_user` (`user_id`),
  ADD KEY `idx_vpn_connections_connected` (`connected_at`);

--
-- Indexes for table `waiting_queue`
--
ALTER TABLE `waiting_queue`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_waiting_queue_order` (`order_id`),
  ADD KEY `idx_waiting_queue_user` (`user_id`),
  ADD KEY `idx_waiting_queue_plan` (`plan_id`),
  ADD KEY `idx_waiting_queue_category` (`category_id`),
  ADD KEY `idx_waiting_queue_duration_processed` (`duration`,`processed_at`,`id`),
  ADD KEY `idx_waiting_queue_traffic` (`traffic_type`,`traffic_limit_gb`),
  ADD KEY `idx_waiting_queue_status` (`status`),
  ADD KEY `idx_waiting_queue_open` (`duration`,`processed_at`,`id`);

--
-- Indexes for table `wallet_transactions`
--
ALTER TABLE `wallet_transactions`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_wallet_user` (`user_id`),
  ADD KEY `idx_wallet_type` (`type`),
  ADD KEY `idx_wallet_status` (`status`),
  ADD KEY `idx_wallet_crypto` (`crypto_payment_id`);

--
-- AUTO_INCREMENT for dumped tables
--

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

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

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

--
-- AUTO_INCREMENT for table `app_migrations`
--
ALTER TABLE `app_migrations`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

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

--
-- AUTO_INCREMENT for table `credentials`
--
ALTER TABLE `credentials`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

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

--
-- AUTO_INCREMENT for table `deliveries`
--
ALTER TABLE `deliveries`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `discount_codes`
--
ALTER TABLE `discount_codes`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `discount_usages`
--
ALTER TABLE `discount_usages`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

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

--
-- AUTO_INCREMENT for table `faq_items`
--
ALTER TABLE `faq_items`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

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

--
-- AUTO_INCREMENT for table `forced_channels`
--
ALTER TABLE `forced_channels`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

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

--
-- AUTO_INCREMENT for table `orders`
--
ALTER TABLE `orders`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

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

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

--
-- AUTO_INCREMENT for table `plans`
--
ALTER TABLE `plans`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `plan_categories`
--
ALTER TABLE `plan_categories`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

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

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

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

--
-- AUTO_INCREMENT for table `schema_migrations`
--
ALTER TABLE `schema_migrations`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `service_expiry_reminders`
--
ALTER TABLE `service_expiry_reminders`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `support_messages`
--
ALTER TABLE `support_messages`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `support_tickets`
--
ALTER TABLE `support_tickets`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

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

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

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

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

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

--
-- AUTO_INCREMENT for table `waiting_queue`
--
ALTER TABLE `waiting_queue`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

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

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

--
-- Structure for view `vw_active_plan_categories`
--
DROP TABLE IF EXISTS `vw_active_plan_categories`;

CREATE ALGORITHM=UNDEFINED SQL SECURITY INVOKER VIEW `vw_active_plan_categories`  AS SELECT `plan_categories`.`id` AS `id`, `plan_categories`.`code` AS `code`, `plan_categories`.`service_type` AS `service_type`, `plan_categories`.`name` AS `name`, `plan_categories`.`months` AS `months`, `plan_categories`.`traffic_type` AS `traffic_type`, `plan_categories`.`traffic_limit_gb` AS `traffic_limit_gb`, `plan_categories`.`is_active` AS `is_active`, `plan_categories`.`display_order` AS `display_order`, `plan_categories`.`sort_order` AS `sort_order`, `plan_categories`.`deleted_at` AS `deleted_at`, `plan_categories`.`created_at` AS `created_at`, `plan_categories`.`updated_at` AS `updated_at` FROM `plan_categories` WHERE `plan_categories`.`is_active` = 1 AND `plan_categories`.`deleted_at` is null ;

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

--
-- Structure for view `vw_available_credentials`
--
DROP TABLE IF EXISTS `vw_available_credentials`;

CREATE ALGORITHM=UNDEFINED SQL SECURITY INVOKER VIEW `vw_available_credentials`  AS SELECT `credentials`.`id` AS `id`, `credentials`.`category_id` AS `category_id`, `credentials`.`email` AS `email`, `credentials`.`username` AS `username`, `credentials`.`password` AS `password`, `credentials`.`duration` AS `duration`, `credentials`.`months` AS `months`, `credentials`.`max_seats` AS `max_seats`, `credentials`.`traffic_type` AS `traffic_type`, `credentials`.`traffic_limit_gb` AS `traffic_limit_gb`, `credentials`.`used_seats` AS `used_seats`, `credentials`.`assigned_user_id` AS `assigned_user_id`, `credentials`.`assigned_order_id` AS `assigned_order_id`, `credentials`.`first_connected_at` AS `first_connected_at`, `credentials`.`first_connection_at` AS `first_connection_at`, `credentials`.`expires_at` AS `expires_at`, `credentials`.`plan_id` AS `plan_id`, `credentials`.`protocol` AS `protocol`, `credentials`.`sellable_until` AS `sellable_until`, `credentials`.`is_active` AS `is_active`, `credentials`.`sales_paused` AS `sales_paused`, `credentials`.`is_sold` AS `is_sold`, `credentials`.`status` AS `status`, `credentials`.`sold_to_user_id` AS `sold_to_user_id`, `credentials`.`order_id` AS `order_id`, `credentials`.`sold_at` AS `sold_at`, `credentials`.`delivered_at` AS `delivered_at`, `credentials`.`disabled_at` AS `disabled_at`, `credentials`.`deleted_at` AS `deleted_at`, `credentials`.`warning_5d_sent` AS `warning_5d_sent`, `credentials`.`capacity_warn_sent` AS `capacity_warn_sent`, `credentials`.`created_by` AS `created_by`, `credentials`.`created_at` AS `created_at`, `credentials`.`updated_at` AS `updated_at` FROM `credentials` WHERE `credentials`.`is_active` = 1 AND `credentials`.`used_seats` = 0 AND coalesce(`credentials`.`is_sold`,0) = 0 AND lcase(coalesce(`credentials`.`status`,'available')) in ('available','ready') AND `credentials`.`deleted_at` is null ;

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

--
-- Structure for view `vw_user_services`
--
DROP TABLE IF EXISTS `vw_user_services`;

CREATE ALGORITHM=UNDEFINED SQL SECURITY INVOKER VIEW `vw_user_services`  AS SELECT `d`.`id` AS `delivery_id`, `d`.`order_id` AS `order_id`, `d`.`user_id` AS `user_id`, `d`.`credential_id` AS `credential_id`, `d`.`vpn_account_id` AS `vpn_account_id`, coalesce(`d`.`username`,`c`.`username`,`c`.`email`,`va`.`username`) AS `username`, coalesce(`d`.`password`,`c`.`password`,`va`.`password`) AS `password`, coalesce(`c`.`first_connected_at`,`c`.`first_connection_at`,`va`.`first_connection_at`) AS `first_connection_at`, coalesce(`c`.`expires_at`,`va`.`expires_at`) AS `expires_at`, `d`.`delivered_at` AS `delivered_at`, `d`.`status` AS `status` FROM ((`deliveries` `d` left join `credentials` `c` on(`c`.`id` = `d`.`credential_id`)) left join `vpn_accounts` `va` on(`va`.`id` = `d`.`vpn_account_id`)) ;

-- --------------------------------------------------------
-- Clean production seed data: no users, no orders, no tickets, no logs, no credentials.
-- Admin ids and secrets are loaded from .env, not from SQL.

INSERT INTO `settings` (`key_name`, `value`) VALUES
('shop_public_name', 'GEM ACC'),
('card_number', ''),
('card_owner_name', ''),
('bank_cards', ''),
('bank_cards_index', '0'),
('support_group', ''),
('sales_enabled', '1'),
('sms_auto_approve_enabled', '1'),
('sms_auto_approve_window_hours', '48'),
('sms_auto_approve_tolerance_rial', '0'),
('sms_auto_approve_require_receipt', '0'),
('sms_auto_approve_allowed_senders', ''),
('sms_auto_approve_notify_admins', '1'),
('sales_closed_message', 'فروش موقتاً بسته است. لطفاً بعداً دوباره تلاش کنید.'),
('signup_bonus_toman', '15000'),
('card_payment_enabled', '1'),
('manual_crypto_enabled', '1'),
('manual_crypto_usdt_address', ''),
('manual_crypto_trx_address', ''),
('manual_crypto_usdt_network', 'BEP20 / BNB Smart Chain'),
('manual_crypto_trx_network', 'TRON'),
('manual_crypto_receipt_help', 'بعد از واریز، عکس رسید یا هش تراکنش را ارسال کنید.'),
('manual_crypto_usdt_irt_rate', '0'),
('manual_crypto_trx_irt_rate', '0'),
('manual_crypto_live_rates_enabled', '0'),
('plisio_enabled', '0'),
('plisio_api_key', ''),
('plisio_usd_rate_toman', '60000'),
('plisio_min_invoice_usd', '5.01'),
('plisio_currencies', 'USDT_BSC,TRX,BTC,LTC'),
('plisio_allow_all_currencies', '1'),
('swapwallet_enabled', '0'),
('swapwallet_api_key', ''),
('swapwallet_payment_username', ''),
('swapwallet_invoice_endpoint', ''),
('swapwallet_base_url', 'https://swapwallet.app/api'),
('swapwallet_default_token', 'USDT'),
('swapwallet_default_network', 'TRON'),
('stars_enabled', '0'),
('stars_rate_toman', '7000'),
('stars_pending_auto_cancel_seconds', '15'),
('openvpn_config_url', 'https://laksho1.com'),
('l2tp_server', 's8.laksho1.com'),
('default_payment_tolerance_toman', '50000'),
('volume_payment_tolerance_toman', '30000'),
('openvpn_purchase_price_per_user', '180000'),
('windscribe_purchase_price_per_user', '0'),
('windscribe_month_purchase_total', '1500000'),
('windscribe_month_purchase_seats', '10'),
('windscribe_year_purchase_total', '5000000'),
('windscribe_year_purchase_seats', '15'),
('express_month_purchase_total', '500000'),
('express_month_purchase_seats', '10'),
('express_year_purchase_per_user', '250000')
ON DUPLICATE KEY UPDATE `value` = VALUES(`value`);

INSERT INTO `plan_categories` (`code`, `service_type`, `service_name`, `name`, `months`, `traffic_type`, `traffic_limit_gb`, `is_active`, `display_order`, `sort_order`) VALUES
('WS_1M_U', 'windscribe', 'Windscribe', 'ویندسکرایب یک‌ماهه', 1, 'unlimited', NULL, 1, 9001, 0),
('WS_1Y_U', 'windscribe', 'Windscribe', 'ویندسکرایب یک‌ساله', 12, 'unlimited', NULL, 1, 9012, 0),
('EXP_1M_U', 'expressvpn', 'ExpressVPN', 'ExpressVPN یک‌ماهه', 1, 'unlimited', NULL, 1, 9201, 0),
('EXP_1Y_U', 'expressvpn', 'ExpressVPN', 'ExpressVPN یک‌ساله', 12, 'unlimited', NULL, 1, 9212, 0),
('OVPN_1M_U', 'openvpn_l2tp', 'OpenVPN | L2TP', 'OpenVPN/L2TP یک‌ماهه نامحدود', 1, 'unlimited', NULL, 1, 100, 0),
('OVPN_1Y_U', 'openvpn_l2tp', 'OpenVPN | L2TP', 'OpenVPN/L2TP یک‌ساله نامحدود', 12, 'unlimited', NULL, 1, 120, 0)
ON DUPLICATE KEY UPDATE service_type=VALUES(service_type), service_name=VALUES(service_name), name=VALUES(name), months=VALUES(months), traffic_type=VALUES(traffic_type), traffic_limit_gb=VALUES(traffic_limit_gb), is_active=VALUES(is_active), deleted_at=NULL;

INSERT INTO `plans` (`category_id`, `code`, `title`, `duration`, `months`, `seats`, `user_count`, `protocol`, `service_name`, `traffic_type`, `traffic_limit_gb`, `price`, `purchase_price`, `is_active`, `display_order`, `sort_order`)
SELECT pc.id, CONCAT(pc.code, '_', x.users), CONCAT('اشتراک اورجینال Windscribe ', pc.name, ' | ', x.users, ' کاربر'), pc.code, pc.months, x.users, x.users, 'windscribe', 'Windscribe', 'unlimited', NULL, 0, 0, 1, x.users, 0
FROM plan_categories pc JOIN (SELECT 1 users UNION SELECT 2 UNION SELECT 3 UNION SELECT 5) x WHERE pc.code IN ('WS_1M_U','WS_1Y_U')
ON DUPLICATE KEY UPDATE title=VALUES(title), months=VALUES(months), seats=VALUES(seats), user_count=VALUES(user_count), protocol='windscribe', service_name='Windscribe', traffic_type='unlimited', traffic_limit_gb=NULL, is_active=1, deleted_at=NULL;

INSERT INTO `plans` (`category_id`, `code`, `title`, `duration`, `months`, `seats`, `user_count`, `protocol`, `service_name`, `traffic_type`, `traffic_limit_gb`, `price`, `purchase_price`, `is_active`, `display_order`, `sort_order`)
SELECT pc.id, 'EXP_1M_10', 'اشتراک ExpressVPN یک‌ماهه | ۱۰ کاربر', pc.code, 1, 10, 10, 'expressvpn', 'ExpressVPN', 'unlimited', NULL, 900000, 500000, 1, 10, 0 FROM plan_categories pc WHERE pc.code='EXP_1M_U'
ON DUPLICATE KEY UPDATE title=VALUES(title), price=VALUES(price), purchase_price=VALUES(purchase_price), is_active=1, deleted_at=NULL;

INSERT INTO `plans` (`category_id`, `code`, `title`, `duration`, `months`, `seats`, `user_count`, `protocol`, `service_name`, `traffic_type`, `traffic_limit_gb`, `price`, `purchase_price`, `is_active`, `display_order`, `sort_order`)
SELECT pc.id, 'EXP_1Y_1', 'اشتراک ExpressVPN یک‌ساله | ۱ کاربر', pc.code, 12, 1, 1, 'expressvpn', 'ExpressVPN', 'unlimited', NULL, 690000, 250000, 1, 1, 0 FROM plan_categories pc WHERE pc.code='EXP_1Y_U'
ON DUPLICATE KEY UPDATE title=VALUES(title), price=VALUES(price), purchase_price=VALUES(purchase_price), is_active=1, deleted_at=NULL;

INSERT INTO `plans` (`category_id`, `code`, `title`, `duration`, `months`, `seats`, `user_count`, `protocol`, `service_name`, `traffic_type`, `traffic_limit_gb`, `price`, `purchase_price`, `is_active`, `display_order`, `sort_order`)
SELECT pc.id, CONCAT(pc.code, '_', x.users), CONCAT('سرویس OpenVPN/L2TP ', pc.name, ' | ', x.users, ' کاربر'), pc.code, pc.months, x.users, x.users, 'openvpn_l2tp', 'OpenVPN | L2TP', 'unlimited', NULL, 0, 0, 1, x.users, 0
FROM plan_categories pc JOIN (SELECT 1 users UNION SELECT 2 UNION SELECT 3 UNION SELECT 5) x WHERE pc.code IN ('OVPN_1M_U','OVPN_1Y_U')
ON DUPLICATE KEY UPDATE title=VALUES(title), months=VALUES(months), seats=VALUES(seats), user_count=VALUES(user_count), protocol='openvpn_l2tp', service_name='OpenVPN | L2TP', is_active=1, deleted_at=NULL;

INSERT INTO `tutorials` (`service_type`, `device`, `text_content`) VALUES
('windscribe', 'ANDROID', 'آموزش Windscribe برای اندروید را از پنل مدیریت تکمیل کنید.'),
('windscribe', 'IPHONE', 'آموزش Windscribe برای آیفون را از پنل مدیریت تکمیل کنید.'),
('windscribe', 'WINDOWS', 'آموزش Windscribe برای ویندوز را از پنل مدیریت تکمیل کنید.'),
('openvpn_l2tp', 'ANDROID', 'آموزش OpenVPN/L2TP برای اندروید را از پنل مدیریت تکمیل کنید.'),
('openvpn_l2tp', 'IPHONE', 'آموزش OpenVPN/L2TP برای آیفون را از پنل مدیریت تکمیل کنید.'),
('openvpn_l2tp', 'WINDOWS', 'آموزش OpenVPN/L2TP برای ویندوز را از پنل مدیریت تکمیل کنید.'),
('expressvpn', 'ANDROID', 'آموزش ExpressVPN برای اندروید را از پنل مدیریت تکمیل کنید.'),
('expressvpn', 'IPHONE', 'آموزش ExpressVPN برای آیفون را از پنل مدیریت تکمیل کنید.'),
('expressvpn', 'WINDOWS', 'آموزش ExpressVPN برای ویندوز را از پنل مدیریت تکمیل کنید.');

INSERT INTO `schema_migrations` (`version`, `executed_at`) VALUES
('clean_install_2026_06_05', NOW())
ON DUPLICATE KEY UPDATE `executed_at` = VALUES(`executed_at`);

COMMIT;

/*!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 */;