-- https://www.phpmyadmin.net/
--
-- ظ…ط¶ظٹظپ: localhost:3306
-- ظˆظ‚طھ ط§ظ„ط¬ظٹظ„: 25 ط£ظƒطھظˆط¨ط± 2025 ط§ظ„ط³ط§ط¹ط© 15:45
-- ط¥طµط¯ط§ط± ط§ظ„ط®ط§ط¯ظ…: 11.4.8-MariaDB-cll-lve-log
-- ظ†ط³ط®ط© PHP: 8.3.26

START TRANSACTION;



--
-- ظ‚ط§ط¹ط¯ط© ط¨ظٹط§ظ†ط§طھ: `supehgku_test0`
--


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

--
-- ط¨ظ†ظٹط© ط§ظ„ط¬ط¯ظˆظ„ `account_groups`
--

CREATE TABLE `account_groups` (
  `id` int(11) NOT NULL,
  `group_name` varchar(64) NOT NULL,
  `description` text DEFAULT NULL,
  `is_default` tinyint(1) DEFAULT 0 COMMENT 'ط§ظ„ظ…ط¬ظ…ظˆط¹ط© ط§ظ„ط§ظپطھط±ط§ط¶ظٹط©',
  `active` tinyint(1) DEFAULT 1,
  `locked` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'ظ‚ظپظ„ ط§ظ„ظ…ط¬ظ…ظˆط¹ط© ظٹظ…ظ†ط¹ rename/delete',
  `priority` int(11) DEFAULT 0 COMMENT 'ط£ظˆظ„ظˆظٹط© ط§ظ„ط¨ط­ط«',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `group_name_lower` varchar(64) GENERATED ALWAYS AS (lcase(`group_name`)) STORED
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='ظ…ط¬ظ…ظˆط¹ط§طھ ط§ظ„ط­ط³ط§ط¨ط§طھ ظ„طھظ†ط¸ظٹظ… ط§ظ„ظˆطµظˆظ„';

--
-- ط¥ط±ط¬ط§ط¹ ط£ظˆ ط§ط³طھظٹط±ط§ط¯ ط¨ظٹط§ظ†ط§طھ ط§ظ„ط¬ط¯ظˆظ„ `account_groups`
--

INSERT INTO `account_groups` (`id`, `group_name`, `description`, `is_default`, `active`, `locked`, `priority`, `created_at`) VALUES
(1, 'default', 'ط§ظ„ظ…ط¬ظ…ظˆط¹ط© ط§ظ„ط¹ط§ظ…ط© - طھط­طھظˆظٹ ط¬ظ…ظٹط¹ ط§ظ„ط­ط³ط§ط¨ط§طھ', 1, 1, 0, 0, '2025-10-22 19:51:06');

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

--
-- Stand-in structure for view `active_bans`
-- (See below for the actual view)
--
CREATE TABLE `active_bans` (
`id` bigint(20)
,`user_id` bigint(20)
,`account_id` int(11)
,`banned_until` timestamp
,`reason` varchar(255)
,`created_at` timestamp
,`account_name` varchar(64)
,`hours_remaining` bigint(21)
);

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

--
-- ط¨ظ†ظٹط© ط§ظ„ط¬ط¯ظˆظ„ `bot_groups`
--

CREATE TABLE `bot_groups` (
  `bot_id` int(11) NOT NULL,
  `group_id` int(11) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='ط±ط¨ط· ط§ظ„ط¨ظˆطھط§طھ ط¨ط§ظ„ظ…ط¬ظ…ظˆط¹ط§طھ';

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

--
-- ط¨ظ†ظٹط© ط§ظ„ط¬ط¯ظˆظ„ `bot_message_templates`
--

CREATE TABLE `bot_message_templates` (
  `id` int(11) NOT NULL,
  `bot_id` int(11) NOT NULL,
  `template_key` varchar(64) NOT NULL,
  `template_text` text NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='ط±ط¯ظˆط¯ ظ…ط®طµطµط© ظ„ظƒظ„ ط¨ظˆطھ - طھطھط¬ط§ظˆط² ط§ظ„ط±ط¯ظˆط¯ ط§ظ„ط¹ط§ظ…ط© ظپظٹ message_templates';

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

--
-- ط¨ظ†ظٹط© ط§ظ„ط¬ط¯ظˆظ„ `broadcast_jobs`
--

CREATE TABLE `broadcast_jobs` (
  `id` bigint(20) NOT NULL,
  `job_key` varchar(64) NOT NULL COMMENT 'Hash ظپط±ظٹط¯ ظ„ظ…ظ†ط¹ ط§ظ„طھظƒط±ط§ط±',
  `initiator_user_id` bigint(20) NOT NULL COMMENT 'ط§ظ„ظ…ط§ظ„ظƒ ط§ظ„ط°ظٹ ط¨ط¯ط£ ط§ظ„ط¨ط«',
  `target_type` enum('label','all') NOT NULL,
  `target_label` varchar(64) DEFAULT NULL COMMENT 'ط§ط³ظ… ط§ظ„ط¨ظˆطھ ط¥ظ† ظƒط§ظ† label',
  `message_text` text NOT NULL,
  `media_type` enum('text','photo','video') DEFAULT 'text',
  `media_id` varchar(255) DEFAULT NULL,
  `status` enum('pending','running','completed','failed') DEFAULT 'pending',
  `total_recipients` int(11) DEFAULT 0,
  `sent_count` int(11) DEFAULT 0,
  `fail_count` int(11) DEFAULT 0,
  `scheduled_at` timestamp NULL DEFAULT NULL COMMENT 'ظ„ظ„ط¬ط¯ظˆظ„ط© ط§ظ„ظ…ط³طھظ‚ط¨ظ„ظٹط©',
  `started_at` timestamp NULL DEFAULT NULL,
  `completed_at` timestamp NULL DEFAULT NULL,
  `error_message` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='ط¬ط¯ظˆظ„ ظ…ظ‡ط§ظ… ط§ظ„ط¨ط« ط§ظ„ط¢ظ…ظ†';

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

--
-- Stand-in structure for view `current_usage`
-- (See below for the actual view)
--
CREATE TABLE `current_usage` (
`id` bigint(20)
,`user_id` bigint(20)
,`account_id` int(11)
,`day_used` int(11)
,`week_used` int(11)
,`month_used` int(11)
,`day_reset_at` timestamp
,`week_reset_at` timestamp
,`month_reset_at` timestamp
,`updated_at` timestamp
,`account_name` varchar(64)
,`current_day_used` int(11)
,`current_week_used` int(11)
,`current_month_used` int(11)
);

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

--
-- ط¨ظ†ظٹط© ط§ظ„ط¬ط¯ظˆظ„ `group_accounts`
--

CREATE TABLE `group_accounts` (
  `group_id` int(11) NOT NULL,
  `account_id` int(11) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='ط±ط¨ط· ط§ظ„ط­ط³ط§ط¨ط§طھ ط¨ط§ظ„ظ…ط¬ظ…ظˆط¹ط§طھ';

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

--
-- ط¨ظ†ظٹط© ط§ظ„ط¬ط¯ظˆظ„ `limits_bot`
--

CREATE TABLE `limits_bot` (
  `bot_label` varchar(64) NOT NULL,
  `mode` enum('daily','weekly','monthly') NOT NULL,
  `per_day` int(11) NOT NULL,
  `weekly_cap` int(11) DEFAULT NULL,
  `monthly_cap` int(11) DEFAULT NULL,
  `ban_days` int(11) DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='ط­ط¯ظˆط¯ ط®ط§طµط© ظ„ظƒظ„ ط¨ظˆطھ (طھطھط¬ط§ظˆط² ط§ظ„ط­ط¯ظˆط¯ ط§ظ„ط¹ط§ظ…ط©)';

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

--
-- ط¨ظ†ظٹط© ط§ظ„ط¬ط¯ظˆظ„ `limits_global`
--

CREATE TABLE `limits_global` (
  `id` int(11) NOT NULL,
  `mode` enum('daily','weekly','monthly') NOT NULL DEFAULT 'daily' COMMENT 'ط§ظ„ظˆط¶ط¹: ظٹظˆظ…ظٹ/ط£ط³ط¨ظˆط¹ظٹ/ط´ظ‡ط±ظٹ',
  `per_day` int(11) NOT NULL DEFAULT 2 COMMENT 'ط§ظ„ط­ط¯ ط§ظ„ظٹظˆظ…ظٹ (ط¹ط¯ط¯ ط§ظ„ط£ظƒظˆط§ط¯ ط§ظ„ظ…ط³ظ…ظˆط­ ط¨ظ‡ط§ ظپظٹ ط§ظ„ظٹظˆظ…)',
  `weekly_cap` int(11) DEFAULT NULL COMMENT 'ط§ظ„ط³ظ‚ظپ ط§ظ„ط£ط³ط¨ظˆط¹ظٹ (ظ„ظ„ظˆط¶ط¹ weekly ظپظ‚ط·)',
  `monthly_cap` int(11) DEFAULT NULL COMMENT 'ط§ظ„ط³ظ‚ظپ ط§ظ„ط´ظ‡ط±ظٹ (ظ„ظ„ظˆط¶ط¹ monthly ظپظ‚ط·)',
  `ban_days` int(11) DEFAULT NULL COMMENT 'ط¹ط¯ط¯ ط£ظٹط§ظ… ط§ظ„ط­ط¸ط± ط¨ط¹ط¯ ط§ظ„طھط¬ط§ظˆط² (NULL = ظ„ط§ ط­ط¸ط±)',
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='ط§ظ„ط­ط¯ظˆط¯ ط§ظ„ط¹ط§ظ…ط© ط§ظ„ط§ظپطھط±ط§ط¶ظٹط© ظ„ط¬ظ…ظٹط¹ ط§ظ„ط¨ظˆطھط§طھ';

--
-- ط¥ط±ط¬ط§ط¹ ط£ظˆ ط§ط³طھظٹط±ط§ط¯ ط¨ظٹط§ظ†ط§طھ ط§ظ„ط¬ط¯ظˆظ„ `limits_global`
--

INSERT INTO `limits_global` (`id`, `mode`, `per_day`, `weekly_cap`, `monthly_cap`, `ban_days`, `updated_at`) VALUES
(1, 'weekly', 1, 2, NULL, 1000, '2025-10-24 17:09:59');

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

--
-- ط¨ظ†ظٹط© ط§ظ„ط¬ط¯ظˆظ„ `limits_override`
--

CREATE TABLE `limits_override` (
  `account_id` int(11) NOT NULL,
  `mode` enum('daily','weekly','monthly') NOT NULL,
  `per_day` int(11) NOT NULL,
  `cap` int(11) DEFAULT NULL COMMENT 'ط§ظ„ط³ظ‚ظپ (ط£ط³ط¨ظˆط¹ظٹ ط£ظˆ ط´ظ‡ط±ظٹ ط­ط³ط¨ ط§ظ„ظˆط¶ط¹)',
  `ban_days` int(11) DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='طھط¬ط§ظˆط² ط§ظ„ط­ط¯ظˆط¯ ظ„ط­ط³ط§ط¨ ظ…ط­ط¯ط¯ (ط£ط¹ظ„ظ‰ ط£ظˆظ„ظˆظٹط©)';

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

--
-- ط¨ظ†ظٹط© ط§ظ„ط¬ط¯ظˆظ„ `limit_bans`
--

CREATE TABLE `limit_bans` (
  `id` bigint(20) NOT NULL,
  `user_id` bigint(20) NOT NULL COMMENT 'ظ…ط¹ط±ظپ ط§ظ„ظ…ط³طھط®ط¯ظ… ط§ظ„ظ…ط­ط¸ظˆط±',
  `account_id` int(11) NOT NULL COMMENT 'ظ…ط¹ط±ظپ ط§ظ„ط­ط³ط§ط¨',
  `bot_label` varchar(50) NOT NULL COMMENT 'طھط³ظ…ظٹط© ط§ظ„ط¨ظˆطھ',
  `banned_until` timestamp NOT NULL COMMENT 'ط§ظ„ط­ط¸ط± ط³ط§ط±ظٹ ط­طھظ‰ ظ‡ط°ط§ ط§ظ„ظˆظ‚طھ',
  `reason` varchar(255) DEFAULT NULL COMMENT 'ط³ط¨ط¨ ط§ظ„ط­ط¸ط± (weekly_exceeded, monthly_exceeded, manual)',
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='ط³ط¬ظ„ ط§ظ„ط­ط¸ط± ط§ظ„ظ…ط¤ظ‚طھ';

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

--
-- ط¨ظ†ظٹط© ط§ظ„ط¬ط¯ظˆظ„ `limit_counters`
--

CREATE TABLE `limit_counters` (
  `id` bigint(20) NOT NULL,
  `user_id` bigint(20) NOT NULL COMMENT 'ظ…ط¹ط±ظپ ط§ظ„ظ…ط³طھط®ط¯ظ… ظپظٹ Telegram',
  `account_id` int(11) NOT NULL COMMENT 'ظ…ط¹ط±ظپ ط§ظ„ط­ط³ط§ط¨ ظ…ظ† steam_accounts',
  `bot_label` varchar(50) NOT NULL COMMENT 'طھط³ظ…ظٹط© ط§ظ„ط¨ظˆطھ',
  `day_used` int(11) DEFAULT 0 COMMENT 'ط¹ط¯ط¯ ط§ظ„ط£ظƒظˆط§ط¯ ط§ظ„ظ…ط³طھط®ط¯ظ…ط© ط§ظ„ظٹظˆظ…',
  `week_used` int(11) DEFAULT 0 COMMENT 'ط¹ط¯ط¯ ط§ظ„ط£ظƒظˆط§ط¯ ط§ظ„ظ…ط³طھط®ط¯ظ…ط© ظ‡ط°ط§ ط§ظ„ط£ط³ط¨ظˆط¹',
  `month_used` int(11) DEFAULT 0 COMMENT 'ط¹ط¯ط¯ ط§ظ„ط£ظƒظˆط§ط¯ ط§ظ„ظ…ط³طھط®ط¯ظ…ط© ظ‡ط°ط§ ط§ظ„ط´ظ‡ط±',
  `day_reset_at` timestamp NULL DEFAULT NULL COMMENT 'ظ…ظˆط¹ط¯ ط¥ط¹ط§ط¯ط© طھط¹ظٹظٹظ† ط§ظ„ط¹ط¯ط§ط¯ ط§ظ„ظٹظˆظ…ظٹ',
  `week_reset_at` timestamp NULL DEFAULT NULL COMMENT 'ظ…ظˆط¹ط¯ ط¥ط¹ط§ط¯ط© طھط¹ظٹظٹظ† ط§ظ„ط¹ط¯ط§ط¯ ط§ظ„ط£ط³ط¨ظˆط¹ظٹ',
  `month_reset_at` timestamp NULL DEFAULT NULL COMMENT 'ظ…ظˆط¹ط¯ ط¥ط¹ط§ط¯ط© طھط¹ظٹظٹظ† ط§ظ„ط¹ط¯ط§ط¯ ط§ظ„ط´ظ‡ط±ظٹ',
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='ط¹ط¯ط§ط¯ط§طھ ط§ظ„ط§ط³طھط®ط¯ط§ظ… ظ„ظƒظ„ ظ…ط³طھط®ط¯ظ… أ— ط­ط³ط§ط¨';

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

--
-- ط¨ظ†ظٹط© ط§ظ„ط¬ط¯ظˆظ„ `limit_messages`
--

CREATE TABLE `limit_messages` (
  `event` varchar(32) NOT NULL,
  `text` text NOT NULL,
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='ط±ط³ط§ط¦ظ„ ط§ظ„ط£ط­ط¯ط§ط« ط§ظ„ظ‚ط§ط¨ظ„ط© ظ„ظ„طھط®طµظٹطµ';

--
-- ط¥ط±ط¬ط§ط¹ ط£ظˆ ط§ط³طھظٹط±ط§ط¯ ط¨ظٹط§ظ†ط§طھ ط§ظ„ط¬ط¯ظˆظ„ `limit_messages`
--

INSERT INTO `limit_messages` (`event`, `text`, `updated_at`) VALUES
('on_banned', 'ًںڑ« طھظ… ط­ط¸ط±ظƒ ظ…ظ† ط§ظ„ط­ط³ط§ط¨ {account} ظ„ظ…ط¯ط© {ban_days} ط£ظٹط§ظ….\n\nًں“… ط§ظ„ط­ط¸ط± ظٹظ†طھظ‡ظٹ ظپظٹ: {banned_until}\n\nط§ظ„ط³ط¨ط¨: طھط¬ط§ظˆط²طھ ط§ظ„ط­ط¯ ط§ظ„ظ…ط³ظ…ظˆط­.', '2025-10-24 12:54:02'),
('on_daily_near', 'âڑ ï¸ڈ طھظ†ط¨ظٹظ‡: ط§ظ‚طھط±ط¨طھ ظ…ظ† ط­ط¯ظƒ ط§ظ„ظٹظˆظ…ظٹ!\n\nًں“ٹ ط§ظ„ط§ط³طھط®ط¯ط§ظ…: {day_used}/{per_day}\nًں’ژ ط§ظ„ظ…طھط¨ظ‚ظٹ: {remaining} ط·ظ„ط¨ط§طھ\nًں”„ ط¥ط¹ط§ط¯ط© ط§ظ„طھط¹ظٹظٹظ†: {reset_time}', '2025-10-24 12:54:02'),
('on_limit_hit', 'âڈ³ ظ„ظ‚ط¯ ط§ط³طھظ‡ظ„ظƒطھ ط­ط¯ظƒ ط§ظ„ظٹظˆظ…ظٹ ({day_used}/{per_day}) ظ„ظ„ط­ط³ط§ط¨ {account}.\n\nًں”„ ط¥ط¹ط§ط¯ط© ط§ظ„طھط¹ظٹظٹظ†: {reset_time}\n\nًں’، طھظˆط§طµظ„ ظ…ط¹ ط§ظ„ظ…ط§ظ„ظƒ ظ„ط²ظٹط§ط¯ط© ط­ط¯ظˆط¯ظƒ.', '2025-10-24 12:54:02'),
('on_monthly_near', 'âڑ ï¸ڈ طھظ†ط¨ظٹظ‡: ط§ظ‚طھط±ط¨طھ ظ…ظ† ط§ظ„ط­ط¯ ط§ظ„ط´ظ‡ط±ظٹ!\n\nًں“ٹ ط§ظ„ط§ط³طھط®ط¯ط§ظ…: {month_used}/{monthly_cap}\nًں’ژ ط§ظ„ظ…طھط¨ظ‚ظٹ: {remaining} ط·ظ„ط¨ط§طھ\nًں”„ ط¥ط¹ط§ط¯ط© ط§ظ„طھط¹ظٹظٹظ†: ط¨ط¯ط§ظٹط© ط§ظ„ط´ظ‡ط± ط§ظ„ظ‚ط§ط¯ظ…', '2025-10-24 12:54:02'),
('on_share_warning', 'âڑ ï¸ڈ طھط­ط°ظٹط±: ظ‡ط°ط§ ظ‡ظˆ ط§ظ„ط·ظ„ط¨ ط§ظ„ط±ط§ط¨ط¹ ظ‡ط°ط§ ط§ظ„ط£ط³ط¨ظˆط¹!\n\nًں”’ ظ„ط§ طھط´ط§ط±ظƒ ط§ظ„ط­ط³ط§ط¨ {account} ظ…ط¹ ط¢ط®ط±ظٹظ†.\n\nًں“ٹ ط§ظ„ط§ط³طھط®ط¯ط§ظ… ط§ظ„ط£ط³ط¨ظˆط¹ظٹ: {week_used}/{weekly_cap}\nâ›”ï¸ڈ ط§ظ„ط­ط¯ ط§ظ„ط£ظ‚طµظ‰: {weekly_cap} ط·ظ„ط¨ط§طھ/ط£ط³ط¨ظˆط¹\nًںڑ« ط§ظ„طھط¬ط§ظˆط² ظٹط¤ط¯ظٹ ظ„ظ„ط­ط¸ط± ظ„ظ…ط¯ط© {ban_days} ط£ظٹط§ظ….', '2025-10-24 12:54:02'),
('on_unbanned', 'âœ… <b>طھظ… ط¥ظ„ط؛ط§ط، ط§ظ„ط­ط¸ط±</b>\n\nظٹظ…ظƒظ†ظƒ ط§ظ„ط¢ظ† ط§ط³طھط®ط¯ط§ظ… ط­ط³ط§ط¨ <code>{account}</code> ظ…ط±ط© ط£ط®ط±ظ‰.\n\nâڑ ï¸ڈ ظٹظڈط±ط¬ظ‰ ط§ظ„ط§ظ„طھط²ط§ظ… ط¨ط§ظ„ط­ط¯ظˆط¯ ظ„طھط¬ظ†ط¨ ط§ظ„ط­ط¸ط± ظ…ط¬ط¯ط¯ط§ظ‹.', '2025-10-23 22:44:50'),
('on_weekly_near', 'âڑ ï¸ڈ طھظ†ط¨ظٹظ‡: ط§ظ‚طھط±ط¨طھ ظ…ظ† ط§ظ„ط­ط¯ ط§ظ„ط£ط³ط¨ظˆط¹ظٹ!\n\nًں“ٹ ط§ظ„ط§ط³طھط®ط¯ط§ظ…: {week_used}/{weekly_cap}\nًں’ژ ط§ظ„ظ…طھط¨ظ‚ظٹ: {remaining} ط·ظ„ط¨ط§طھ\nًں”„ ط¥ط¹ط§ط¯ط© ط§ظ„طھط¹ظٹظٹظ†: {reset_time}', '2025-10-24 12:54:02');

--
-- ط§ظ„ظ‚ظˆط§ط¯ط­ `steam_accounts`
--
DELIMITER $$
END
$$
DELIMITER ;

--
-- ط§ظ„ظ‚ظˆط§ط¯ط­ `sub_bots`
--
DELIMITER $$
END
$$
DELIMITER ;

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

--
-- ط¨ظ†ظٹط© ط§ظ„ط¬ط¯ظˆظ„ `system_logs`
--

CREATE TABLE `system_logs` (
  `id` bigint(20) NOT NULL,
  `log_level` enum('INFO','WARNING','ERROR','CRITICAL') DEFAULT 'INFO',
  `component` varchar(64) NOT NULL COMMENT 'control_bot, sub_bot, broadcast',
  `message` text NOT NULL,
  `context` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'ط¨ظٹط§ظ†ط§طھ ط¥ط¶ط§ظپظٹط©' CHECK (json_valid(`context`)),
  `user_id` bigint(20) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='ط³ط¬ظ„ط§طھ ط§ظ„ظ†ط¸ط§ظ… ظ„ظ„طھط¯ظ‚ظٹظ‚';

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

--
-- ط¨ظ†ظٹط© ط§ظ„ط¬ط¯ظˆظ„ `vouchers`
--

CREATE TABLE `vouchers` (
  `id` bigint(20) NOT NULL,
  `code` varchar(32) NOT NULL,
  `voucher_type` enum('users','days','unlimited') DEFAULT 'users',
  `amount` int(11) NOT NULL COMMENT 'ط¹ط¯ط¯ ط§ظ„ظ…ط³طھط®ط¯ظ…ظٹظ† ط£ظˆ ط§ظ„ط£ظٹط§ظ…',
  `target_label` varchar(64) DEFAULT NULL COMMENT 'ط§ط³ظ… ط§ظ„ط¨ظˆطھ ط§ظ„ظ…ط­ط¯ط¯ ط£ظˆ NULL ظ„ظ„ظƒظ„',
  `max_uses` int(11) DEFAULT 1 COMMENT 'ط¹ط¯ط¯ ظ…ط±ط§طھ ط§ظ„ط§ط³طھط®ط¯ط§ظ… ط§ظ„ظ…ط³ظ…ظˆط­',
  `current_uses` int(11) DEFAULT 0 COMMENT 'ط¹ط¯ط¯ ط§ظ„ط§ط³طھط®ط¯ط§ظ…ط§طھ ط§ظ„ط­ط§ظ„ظٹط©',
  `expires_at` timestamp NULL DEFAULT NULL COMMENT 'طھط§ط±ظٹط® ط§ظ†طھظ‡ط§ط، ط§ظ„طµظ„ط§ط­ظٹط©',
  `created_by_user_id` bigint(20) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='ظ‚ط³ط§ط¦ظ… ظ„ط²ظٹط§ط¯ط© ط­ط¯ظˆط¯ ط§ظ„ظ…ط³طھط®ط¯ظ…ظٹظ† ط£ظˆ ط§ظ„ط£ظٹط§ظ…';

--
-- ط¥ط±ط¬ط§ط¹ ط£ظˆ ط§ط³طھظٹط±ط§ط¯ ط¨ظٹط§ظ†ط§طھ ط§ظ„ط¬ط¯ظˆظ„ `vouchers`
--

INSERT INTO `vouchers` (`id`, `code`, `voucher_type`, `amount`, `target_label`, `max_uses`, `current_uses`, `expires_at`, `created_by_user_id`, `created_at`) VALUES
(1, 'V7CDC741AB9', 'users', 200, NULL, 5, 5, NULL, 5458195623, '2025-10-22 22:53:04'),
(2, 'VC8B023B368', 'users', 200, NULL, 1, 1, NULL, 5458195623, '2025-10-22 22:55:28'),
(3, 'V41F5ED6080', 'users', 200, NULL, 1, 1, NULL, 5458195623, '2025-10-22 22:58:18'),
(4, 'VDA3EEA5221', 'users', 200, NULL, 1, 0, NULL, 5458195623, '2025-10-22 22:59:04'),
(5, 'V0A744D4400', 'users', 100000, NULL, 1, 1, NULL, 5458195623, '2025-10-23 21:27:09'),
(6, 'V3D412A162D', 'users', 100000, NULL, 1, 1, NULL, 5458195623, '2025-10-24 17:36:20'),
(7, 'V0BD6CE01F0', 'users', 55, '3', 1, 1, NULL, 5458195623, '2025-10-24 17:37:08'),
(8, 'VEAD32AF223', 'users', 55, NULL, 3, 3, NULL, 5458195623, '2025-10-24 17:38:18');

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

--
-- ط¨ظ†ظٹط© ط§ظ„ط¬ط¯ظˆظ„ `voucher_usage`
--

CREATE TABLE `voucher_usage` (
  `id` bigint(20) NOT NULL,
  `voucher_code` varchar(64) NOT NULL,
  `bot_id` int(11) DEFAULT NULL,
  `used_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='طھطھط¨ط¹ ط§ط³طھط®ط¯ط§ظ… ط§ظ„ظ‚ط³ط§ط¦ظ… ظ…ظ† ظ‚ط¨ظ„ ط§ظ„ط¨ظˆطھط§طھ';

--
-- ط¥ط±ط¬ط§ط¹ ط£ظˆ ط§ط³طھظٹط±ط§ط¯ ط¨ظٹط§ظ†ط§طھ ط§ظ„ط¬ط¯ظˆظ„ `voucher_usage`
--

INSERT INTO `voucher_usage` (`id`, `voucher_code`, `bot_id`, `used_at`) VALUES
(1, 'V7CDC741AB9', NULL, '2025-10-22 18:53:28'),
(2, 'V7CDC741AB9', NULL, '2025-10-22 18:54:33'),
(3, 'V7CDC741AB9', NULL, '2025-10-22 18:54:43'),
(4, 'V7CDC741AB9', NULL, '2025-10-22 18:55:12'),
(5, 'V7CDC741AB9', NULL, '2025-10-22 18:55:13'),
(6, 'VC8B023B368', NULL, '2025-10-22 18:55:46'),
(7, 'V41F5ED6080', NULL, '2025-10-22 18:58:26'),
(8, 'V0A744D4400', NULL, '2025-10-23 17:27:24'),
(9, 'V3D412A162D', NULL, '2025-10-24 13:36:37'),
(10, 'V0BD6CE01F0', NULL, '2025-10-24 13:37:24'),
(11, 'VEAD32AF223', NULL, '2025-10-24 13:38:30'),
(12, 'VEAD32AF223', NULL, '2025-10-24 13:38:33'),
(13, 'VEAD32AF223', NULL, '2025-10-24 13:38:35');

--
-- Indexes for dumped tables
--

--
-- ظپظ‡ط§ط±ط³ ظ„ظ„ط¬ط¯ظˆظ„ `account_groups`
--
ALTER TABLE `account_groups`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `group_name` (`group_name`),
  ADD UNIQUE KEY `idx_unique_group_name_lower` (`group_name_lower`),
  ADD KEY `idx_default` (`is_default`),
  ADD KEY `idx_priority` (`priority`),
  ADD KEY `idx_active` (`active`);

--
-- ظپظ‡ط§ط±ط³ ظ„ظ„ط¬ط¯ظˆظ„ `bot_groups`
--
ALTER TABLE `bot_groups`
  ADD PRIMARY KEY (`bot_id`,`group_id`),
  ADD KEY `group_id` (`group_id`);

--
-- ظپظ‡ط§ط±ط³ ظ„ظ„ط¬ط¯ظˆظ„ `bot_message_templates`
--
ALTER TABLE `bot_message_templates`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `unique_bot_template` (`bot_id`,`template_key`),
  ADD KEY `idx_bot_id` (`bot_id`),
  ADD KEY `idx_template_key` (`template_key`);

--
-- ظپظ‡ط§ط±ط³ ظ„ظ„ط¬ط¯ظˆظ„ `broadcast_jobs`
--
ALTER TABLE `broadcast_jobs`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `job_key` (`job_key`),
  ADD KEY `idx_status` (`status`,`scheduled_at`),
  ADD KEY `idx_initiator` (`initiator_user_id`),
  ADD KEY `idx_job_key` (`job_key`);

--
-- ظپظ‡ط§ط±ط³ ظ„ظ„ط¬ط¯ظˆظ„ `group_accounts`
--
ALTER TABLE `group_accounts`
  ADD PRIMARY KEY (`group_id`,`account_id`),
  ADD KEY `account_id` (`account_id`);

--
-- ظپظ‡ط§ط±ط³ ظ„ظ„ط¬ط¯ظˆظ„ `limits_bot`
--
ALTER TABLE `limits_bot`
  ADD PRIMARY KEY (`bot_label`),
  ADD KEY `idx_mode` (`mode`);

--
-- ظپظ‡ط§ط±ط³ ظ„ظ„ط¬ط¯ظˆظ„ `limits_global`
--
ALTER TABLE `limits_global`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_mode` (`mode`);

--
-- ظپظ‡ط§ط±ط³ ظ„ظ„ط¬ط¯ظˆظ„ `limits_override`
--
ALTER TABLE `limits_override`
  ADD PRIMARY KEY (`account_id`),
  ADD KEY `idx_mode` (`mode`);

--
-- ظپظ‡ط§ط±ط³ ظ„ظ„ط¬ط¯ظˆظ„ `limit_bans`
--
ALTER TABLE `limit_bans`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `unique_user_account_bot_ban` (`user_id`,`account_id`,`bot_label`),
  ADD KEY `idx_user` (`user_id`),
  ADD KEY `idx_account` (`account_id`),
  ADD KEY `idx_until` (`banned_until`),
  ADD KEY `idx_active_bans` (`banned_until`,`user_id`),
  ADD KEY `idx_bot_bans` (`bot_label`);

--
-- ظپظ‡ط§ط±ط³ ظ„ظ„ط¬ط¯ظˆظ„ `limit_counters`
--
ALTER TABLE `limit_counters`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `unique_user_account_bot` (`user_id`,`account_id`,`bot_label`),
  ADD KEY `idx_user` (`user_id`),
  ADD KEY `idx_account` (`account_id`),
  ADD KEY `idx_day_reset` (`day_reset_at`),
  ADD KEY `idx_week_reset` (`week_reset_at`),
  ADD KEY `idx_month_reset` (`month_reset_at`),
  ADD KEY `idx_user_account_day` (`user_id`,`account_id`,`day_used`),
  ADD KEY `idx_bot_counters` (`bot_label`);

--
-- ظپظ‡ط§ط±ط³ ظ„ظ„ط¬ط¯ظˆظ„ `limit_messages`
--
ALTER TABLE `limit_messages`
  ADD PRIMARY KEY (`event`);

--
-- ظپظ‡ط§ط±ط³ ظ„ظ„ط¬ط¯ظˆظ„ `system_logs`
--
ALTER TABLE `system_logs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_level_time` (`log_level`,`created_at`),
  ADD KEY `idx_component` (`component`),
  ADD KEY `idx_user` (`user_id`),
  ADD KEY `idx_component_time` (`component`,`created_at`),
  ADD KEY `idx_user_time` (`user_id`,`created_at`);

--
-- ظپظ‡ط§ط±ط³ ظ„ظ„ط¬ط¯ظˆظ„ `vouchers`
--
ALTER TABLE `vouchers`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `code` (`code`),
  ADD KEY `idx_code` (`code`),
  ADD KEY `idx_type` (`voucher_type`),
  ADD KEY `idx_active` (`current_uses`,`max_uses`),
  ADD KEY `idx_creator` (`created_by_user_id`);

--
-- ظپظ‡ط§ط±ط³ ظ„ظ„ط¬ط¯ظˆظ„ `voucher_usage`
--
ALTER TABLE `voucher_usage`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_voucher_code` (`voucher_code`),
  ADD KEY `idx_bot_id` (`bot_id`),
  ADD KEY `idx_used_at` (`used_at`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `account_groups`
--
ALTER TABLE `account_groups`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;

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

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

--
-- AUTO_INCREMENT for table `limits_global`
--
ALTER TABLE `limits_global`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `limit_bans`
--
ALTER TABLE `limit_bans`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

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

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

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

--
-- AUTO_INCREMENT for table `voucher_usage`
--
ALTER TABLE `voucher_usage`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=16;

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

--
-- Structure for view `active_bans`
--

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

--
-- Structure for view `current_usage`
--

--
-- ظ‚ظٹظˆط¯ ط§ظ„ط¬ط¯ط§ظˆظ„ `bot_groups`
--
ALTER TABLE `bot_groups`
  ADD CONSTRAINT `bot_groups_ibfk_1` FOREIGN KEY (`bot_id`) REFERENCES `sub_bots` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `bot_groups_ibfk_2` FOREIGN KEY (`group_id`) REFERENCES `account_groups` (`id`) ON DELETE CASCADE;

--
-- ظ‚ظٹظˆط¯ ط§ظ„ط¬ط¯ط§ظˆظ„ `bot_message_templates`
--
ALTER TABLE `bot_message_templates`
  ADD CONSTRAINT `bot_message_templates_ibfk_1` FOREIGN KEY (`bot_id`) REFERENCES `sub_bots` (`id`) ON DELETE CASCADE;

--
-- ظ‚ظٹظˆط¯ ط§ظ„ط¬ط¯ط§ظˆظ„ `group_accounts`
--
ALTER TABLE `group_accounts`
  ADD CONSTRAINT `group_accounts_ibfk_1` FOREIGN KEY (`group_id`) REFERENCES `account_groups` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `group_accounts_ibfk_2` FOREIGN KEY (`account_id`) REFERENCES `steam_accounts` (`id`) ON DELETE CASCADE;

--
-- ظ‚ظٹظˆط¯ ط§ظ„ط¬ط¯ط§ظˆظ„ `limits_bot`
--
ALTER TABLE `limits_bot`
  ADD CONSTRAINT `limits_bot_ibfk_1` FOREIGN KEY (`bot_label`) REFERENCES `sub_bots` (`label`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- ظ‚ظٹظˆط¯ ط§ظ„ط¬ط¯ط§ظˆظ„ `limits_override`
--
ALTER TABLE `limits_override`
  ADD CONSTRAINT `limits_override_ibfk_1` FOREIGN KEY (`account_id`) REFERENCES `steam_accounts` (`id`) ON DELETE CASCADE;

--
-- ظ‚ظٹظˆط¯ ط§ظ„ط¬ط¯ط§ظˆظ„ `limit_bans`
--
ALTER TABLE `limit_bans`
  ADD CONSTRAINT `fk_bans_bot_label` FOREIGN KEY (`bot_label`) REFERENCES `sub_bots` (`label`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `limit_bans_ibfk_1` FOREIGN KEY (`account_id`) REFERENCES `steam_accounts` (`id`) ON DELETE CASCADE;

--
-- ظ‚ظٹظˆط¯ ط§ظ„ط¬ط¯ط§ظˆظ„ `limit_counters`
--
ALTER TABLE `limit_counters`
  ADD CONSTRAINT `fk_counters_bot_label` FOREIGN KEY (`bot_label`) REFERENCES `sub_bots` (`label`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `limit_counters_ibfk_1` FOREIGN KEY (`account_id`) REFERENCES `steam_accounts` (`id`) ON DELETE CASCADE;

--
-- ظ‚ظٹظˆط¯ ط§ظ„ط¬ط¯ط§ظˆظ„ `voucher_usage`
--
ALTER TABLE `voucher_usage`
  ADD CONSTRAINT `voucher_usage_ibfk_1` FOREIGN KEY (`voucher_code`) REFERENCES `vouchers` (`code`) ON DELETE CASCADE,
  ADD CONSTRAINT `voucher_usage_ibfk_2` FOREIGN KEY (`bot_id`) REFERENCES `sub_bots` (`id`) ON DELETE SET NULL;
COMMIT;


