-- CS2 Bot League — full schema
-- Import into your existing database (phpMyAdmin: select DB first, then import).

-- ---------------------------------------------------------------------------
-- Settings (key-value overrides)
-- ---------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS {{prefix}}settings (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    setting_key VARCHAR(100) NOT NULL UNIQUE,
    setting_value TEXT NULL,
    updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ---------------------------------------------------------------------------
-- Web admins (panel login)
-- ---------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS {{prefix}}web_admins (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(100) NOT NULL UNIQUE,
    password_hash VARCHAR(255) NOT NULL,
    display_name VARCHAR(150) NULL,
    is_active TINYINT(1) NOT NULL DEFAULT 1,
    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;

INSERT INTO {{prefix}}web_admins (username, password_hash, display_name)
VALUES ('admin', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'Administrator')
ON DUPLICATE KEY UPDATE username = username;


-- ---------------------------------------------------------------------------
-- Authorized Telegram groups
-- ---------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS {{prefix}}authorized_groups (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    chat_id BIGINT NOT NULL UNIQUE,
    title VARCHAR(255) NULL,
    is_active TINYINT(1) NOT NULL DEFAULT 1,
    created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ---------------------------------------------------------------------------
-- Leagues
-- ---------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS {{prefix}}leagues (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(255) NOT NULL,
    type ENUM('wingman', 'competitive') NOT NULL DEFAULT 'competitive',
    description TEXT NULL,
    image_path VARCHAR(500) NULL,
    min_players INT UNSIGNED NOT NULL DEFAULT 2,
    max_players INT UNSIGNED NOT NULL DEFAULT 32,
    registration_fee BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Amount in Toman',
    registration_starts_at DATETIME NULL,
    registration_ends_at DATETIME NULL,
    status ENUM('draft', 'active', 'registration_closed', 'in_progress', 'completed', 'cancelled') NOT NULL DEFAULT 'draft',
    payment_gateway ENUM('zarinpal', 'sepal', 'digipay') NOT NULL DEFAULT 'zarinpal',
    payment_gateways JSON NULL,
    bracket_type ENUM('single_elimination', 'double_elimination', 'round_robin') NULL,
    created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    INDEX idx_leagues_status (status),
    INDEX idx_leagues_type (type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ---------------------------------------------------------------------------
-- Registrations
-- ---------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS {{prefix}}registrations (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    league_id INT UNSIGNED NOT NULL,
    telegram_user_id BIGINT NOT NULL,
    telegram_username VARCHAR(100) NULL,
    display_name VARCHAR(150) NULL,
    photo_path VARCHAR(500) NULL COMMENT 'Legacy; user raw photo stored on {{prefix}}bot_users.raw_profile_image_path',
    competition_profile_path VARCHAR(500) NULL COMMENT 'Admin-uploaded competition profile per league',
    status ENUM('pending_approval', 'awaiting_payment', 'paid', 'cancelled', 'rejected') NOT NULL DEFAULT 'pending_approval',
    payment_id INT UNSIGNED NULL,
    created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    UNIQUE KEY uq_reg_league_user (league_id, telegram_user_id),
    INDEX idx_reg_league (league_id),
    INDEX idx_reg_status (status),
    CONSTRAINT fk_reg_league FOREIGN KEY (league_id) REFERENCES {{prefix}}leagues(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ---------------------------------------------------------------------------
-- Payments
-- ---------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS {{prefix}}payments (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    registration_id INT UNSIGNED NOT NULL,
    league_id INT UNSIGNED NOT NULL,
    telegram_user_id BIGINT NOT NULL,
    gateway ENUM('zarinpal', 'sepal', 'digipay') NOT NULL,
    amount BIGINT UNSIGNED NOT NULL COMMENT 'Base amount in Toman',
    surcharge_percent DECIMAL(5,2) NOT NULL DEFAULT 0,
    final_amount BIGINT UNSIGNED NOT NULL COMMENT 'Final amount in Toman',
    authority VARCHAR(255) NULL COMMENT 'Gateway reference / authority / paymentNumber',
    ref_id VARCHAR(255) NULL COMMENT 'Verified transaction ref',
    status ENUM('pending', 'paid', 'failed', 'cancelled') NOT NULL DEFAULT 'pending',
    sandbox TINYINT(1) NOT NULL DEFAULT 0,
    gateway_response JSON NULL,
    paid_at DATETIME NULL,
    created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    INDEX idx_pay_registration (registration_id),
    INDEX idx_pay_authority (authority),
    INDEX idx_pay_status (status),
    CONSTRAINT fk_pay_registration FOREIGN KEY (registration_id) REFERENCES {{prefix}}registrations(id) ON DELETE CASCADE,
    CONSTRAINT fk_pay_league FOREIGN KEY (league_id) REFERENCES {{prefix}}leagues(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

ALTER TABLE {{prefix}}registrations
    ADD CONSTRAINT fk_reg_payment FOREIGN KEY (payment_id) REFERENCES {{prefix}}payments(id) ON DELETE SET NULL;

-- ---------------------------------------------------------------------------
-- Payment {{prefix}}settings (single row)
-- ---------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS {{prefix}}payment_settings (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    zarinpal_merchant_id VARCHAR(100) NULL,
    zarinpal_sandbox TINYINT(1) NOT NULL DEFAULT 1,
    sepal_api_key VARCHAR(255) NULL,
    sepal_sandbox TINYINT(1) NOT NULL DEFAULT 1,
    digipay_client_id VARCHAR(255) NULL,
    digipay_client_secret VARCHAR(255) NULL,
    digipay_username VARCHAR(255) NULL,
    digipay_password VARCHAR(255) NULL,
    digipay_sandbox TINYINT(1) NOT NULL DEFAULT 1,
    digipay_surcharge_percent DECIMAL(5,2) NOT NULL DEFAULT 0,
    digipay_access_token TEXT NULL,
    digipay_refresh_token TEXT NULL,
    digipay_token_expires_at DATETIME NULL,
    default_gateway ENUM('zarinpal', 'sepal', 'digipay') NOT NULL DEFAULT 'zarinpal',
    gateway_ui JSON NULL,
    payment_agent_enabled TINYINT(1) NOT NULL DEFAULT 0,
    payment_agent_url VARCHAR(500) NULL,
    payment_agent_secret VARCHAR(64) NULL,
    updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO {{prefix}}payment_settings (id, zarinpal_sandbox, sepal_sandbox, digipay_sandbox)
VALUES (1, 1, 1, 1)
ON DUPLICATE KEY UPDATE id = id;

-- ---------------------------------------------------------------------------
-- Teams
-- ---------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS {{prefix}}teams (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    league_id INT UNSIGNED NOT NULL,
    name VARCHAR(150) NOT NULL,
    source ENUM('manual', 'random') NOT NULL DEFAULT 'manual',
    created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_teams_league (league_id),
    CONSTRAINT fk_teams_league FOREIGN KEY (league_id) REFERENCES {{prefix}}leagues(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS {{prefix}}team_members (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    team_id INT UNSIGNED NOT NULL,
    registration_id INT UNSIGNED NOT NULL,
    created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    UNIQUE KEY uq_team_member (team_id, registration_id),
    UNIQUE KEY uq_reg_team (registration_id),
    CONSTRAINT fk_tm_team FOREIGN KEY (team_id) REFERENCES {{prefix}}teams(id) ON DELETE CASCADE,
    CONSTRAINT fk_tm_registration FOREIGN KEY (registration_id) REFERENCES {{prefix}}registrations(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ---------------------------------------------------------------------------
-- Bracket nodes
-- ---------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS {{prefix}}bracket_nodes (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    league_id INT UNSIGNED NOT NULL,
    bracket_side ENUM('winners', 'losers', 'final', 'group') NOT NULL DEFAULT 'winners',
    round_number INT UNSIGNED NOT NULL DEFAULT 1,
    position INT UNSIGNED NOT NULL DEFAULT 0,
    parent_node_id INT UNSIGNED NULL,
    match_id INT UNSIGNED NULL,
    created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_bn_league (league_id),
    CONSTRAINT fk_bn_league FOREIGN KEY (league_id) REFERENCES {{prefix}}leagues(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ---------------------------------------------------------------------------
-- League round {{prefix}}settings (series format per stage)
-- ---------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS {{prefix}}league_round_settings (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    league_id INT UNSIGNED NOT NULL,
    round_number INT UNSIGNED NOT NULL,
    bracket_side ENUM('winners', 'losers', 'final', 'group') NOT NULL DEFAULT 'winners',
    series_format ENUM('bo1', 'bo3', 'bo5') NOT NULL DEFAULT 'bo1',
    created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    UNIQUE KEY uq_league_round_side (league_id, round_number, bracket_side),
    CONSTRAINT fk_lrs_league FOREIGN KEY (league_id) REFERENCES {{prefix}}leagues(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ---------------------------------------------------------------------------
-- Matches
-- ---------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS {{prefix}}matches (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    league_id INT UNSIGNED NOT NULL,
    bracket_node_id INT UNSIGNED NULL,
    round INT UNSIGNED NOT NULL DEFAULT 1,
    bracket_type ENUM('single_elimination', 'double_elimination', 'round_robin', 'playoff') NOT NULL DEFAULT 'single_elimination',
    bracket_side ENUM('winners', 'losers', 'final', 'group') NOT NULL DEFAULT 'winners',
    series_format ENUM('bo1', 'bo3', 'bo5') NOT NULL DEFAULT 'bo1',
    wins_required TINYINT UNSIGNED NOT NULL DEFAULT 1,
    team_a_id INT UNSIGNED NULL,
    team_b_id INT UNSIGNED NULL,
    score_a INT UNSIGNED NULL,
    score_b INT UNSIGNED NULL,
    team_a_wins TINYINT UNSIGNED NOT NULL DEFAULT 0,
    team_b_wins TINYINT UNSIGNED NOT NULL DEFAULT 0,
    winner_id INT UNSIGNED NULL,
    scheduled_at DATETIME NULL,
    status ENUM('scheduled', 'in_progress', 'completed', 'cancelled', 'bye') NOT NULL DEFAULT 'scheduled',
    created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    INDEX idx_matches_league (league_id),
    INDEX idx_matches_status (status),
    CONSTRAINT fk_matches_league FOREIGN KEY (league_id) REFERENCES {{prefix}}leagues(id) ON DELETE CASCADE,
    CONSTRAINT fk_matches_team_a FOREIGN KEY (team_a_id) REFERENCES {{prefix}}teams(id) ON DELETE SET NULL,
    CONSTRAINT fk_matches_team_b FOREIGN KEY (team_b_id) REFERENCES {{prefix}}teams(id) ON DELETE SET NULL,
    CONSTRAINT fk_matches_winner FOREIGN KEY (winner_id) REFERENCES {{prefix}}teams(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

ALTER TABLE {{prefix}}bracket_nodes
    ADD CONSTRAINT fk_bn_match FOREIGN KEY (match_id) REFERENCES {{prefix}}matches(id) ON DELETE SET NULL,
    ADD CONSTRAINT fk_bn_parent FOREIGN KEY (parent_node_id) REFERENCES {{prefix}}bracket_nodes(id) ON DELETE SET NULL;

-- ---------------------------------------------------------------------------
-- Bot texts (CMS)
-- ---------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS {{prefix}}bot_texts (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    text_key VARCHAR(100) NOT NULL UNIQUE,
    content TEXT NOT NULL,
    image_path VARCHAR(500) NULL,
    description VARCHAR(500) NULL,
    available_variables JSON NULL,
    updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ---------------------------------------------------------------------------
-- Bot users (all Telegram users who interacted with the bot)
-- ---------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS {{prefix}}bot_users (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    telegram_user_id BIGINT NOT NULL UNIQUE,
    username VARCHAR(100) NULL,
    first_name VARCHAR(150) NOT NULL DEFAULT '',
    last_name VARCHAR(150) NULL,
    language_code VARCHAR(10) NULL,
    is_bot TINYINT(1) NOT NULL DEFAULT 0,
    is_premium TINYINT(1) NOT NULL DEFAULT 0,
    raw_profile_image_path VARCHAR(500) NULL COMMENT 'User-submitted raw profile photo from registration',
    is_blocked TINYINT(1) NOT NULL DEFAULT 0,
    blocked_reason VARCHAR(500) NULL,
    blocked_at DATETIME NULL,
    first_seen_at DATETIME NOT NULL,
    last_seen_at DATETIME NOT NULL,
    created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    INDEX idx_bot_users_blocked (is_blocked),
    INDEX idx_bot_users_last_seen (last_seen_at),
    INDEX idx_bot_users_username (username)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS {{prefix}}bot_user_chats (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    bot_user_id INT UNSIGNED NOT NULL,
    chat_id BIGINT NOT NULL,
    chat_type ENUM('private', 'group', 'supergroup') NOT NULL,
    chat_title VARCHAR(255) NULL,
    authorized_group_id INT UNSIGNED NULL,
    first_seen_at DATETIME NOT NULL,
    last_seen_at DATETIME NOT NULL,
    created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    UNIQUE KEY uq_bot_user_chat (bot_user_id, chat_id),
    INDEX idx_buc_chat (chat_id),
    INDEX idx_buc_last_seen (last_seen_at),
    CONSTRAINT fk_buc_user FOREIGN KEY (bot_user_id) REFERENCES {{prefix}}bot_users(id) ON DELETE CASCADE,
    CONSTRAINT fk_buc_auth_group FOREIGN KEY (authorized_group_id) REFERENCES {{prefix}}authorized_groups(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ---------------------------------------------------------------------------
-- User conversations (registration state machine)
-- ---------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS {{prefix}}user_conversations (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    telegram_user_id BIGINT NOT NULL UNIQUE,
    step VARCHAR(50) NOT NULL DEFAULT 'idle',
    league_id INT UNSIGNED NULL,
    temp_data JSON NULL,
    updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    INDEX idx_conv_step (step)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ---------------------------------------------------------------------------
-- Audit logs
-- ---------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS {{prefix}}audit_logs (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    actor_type ENUM('web_admin', 'telegram_admin', 'system') NOT NULL DEFAULT 'system',
    actor_id VARCHAR(100) NULL,
    action VARCHAR(100) NOT NULL,
    entity_type VARCHAR(100) NULL,
    entity_id INT UNSIGNED NULL,
    details JSON NULL,
    ip_address VARCHAR(45) NULL,
    created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_audit_action (action),
    INDEX idx_audit_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ---------------------------------------------------------------------------
-- Default bot texts
-- ---------------------------------------------------------------------------
INSERT INTO {{prefix}}bot_texts (text_key, content, description, available_variables) VALUES
('main_menu', 'سلام {user_name}! 👋\n\nبه ربات لیگ CS2 خوش آمدید.\nاز منوی زیر گزینه مورد نظر را انتخاب کنید:', 'Main menu greeting', '["user_name"]'),
('leagues_list', '🏆 لیگ‌های فعال:\n\n{leagues_list}', 'Active {{prefix}}leagues list', '["leagues_list"]'),
('no_active_leagues', 'در حال حاضر لیگ فعالی وجود ندارد.', 'No active {{prefix}}leagues', '[]'),
('registration_ask_name', 'برای ثبت‌نام در لیگ «{league_name}» لطفاً نام خود را وارد کنید:', 'Ask player name', '["league_name"]'),
('registration_ask_photo', 'عالی {player_name}! حالا لطفاً یک عکس از خود ارسال کنید:', 'Ask player photo', '["player_name"]'),
('registration_summary', '📋 خلاصه ثبت‌نام\n\nلیگ: {league_name}\nنام: {player_name}\nمبلغ: {fee_formatted}\n{surcharge_line}\n\n{description}', 'Registration summary before payment', '["league_name","player_name","fee","fee_formatted","surcharge_line","description"]'),
('registration_success', '✅ ثبت‌نام شما در لیگ «{league_name}» تأیید شد.\n\nنام: {player_name}\nشماره پیگیری: {ref_id}\nمبلغ: {fee_formatted}', 'Final admin confirmation after payment review', '["league_name","player_name","ref_id","fee_formatted"]'),
('registration_failed', '❌ پرداخت ناموفق بود. لطفاً دوباره تلاش کنید.', 'Payment failed', '[]'),
('registration_full', 'ظرفیت لیگ «{league_name}» تکمیل شده است.', 'League full', '["league_name"]'),
('registration_closed', 'ثبت‌نام لیگ «{league_name}» بسته است.', 'Registration closed', '["league_name"]'),
('registration_duplicate', 'شما قبلاً در این لیگ ثبت‌نام کرده‌اید.', 'Duplicate registration', '[]'),
('participants_list', '👥 شرکت‌کنندگان لیگ «{league_name}»:\n\n{participants_table}', 'Participants list', '["league_name","participants_table"]'),
('teams_list', '🛡 تیم‌های لیگ «{league_name}»:\n\n{teams_table}', 'Teams list', '["league_name","teams_table"]'),
('matches_list', '⚔️ مسابقات لیگ «{league_name}»:\n\n{matches_table}', 'Matches list', '["league_name","matches_table"]'),
('unauthorized_group', 'این گروه مجاز به استفاده از ربات نیست.', 'Unauthorized group', '[]'),
('admin_added', '✅ ادمین جدید اضافه شد: {admin_id}', 'Admin added', '["admin_id"]'),
('admin_removed', '✅ ادمین حذف شد: {admin_id}', 'Admin removed', '["admin_id"]'),
('payment_button', '💳 پرداخت {amount_formatted}', 'Payment button label', '["amount_formatted"]'),
('user_blocked', '⛔ دسترسی شما به ربات مسدود شده است.\n\nدر صورت نیاز با پشتیبانی تماس بگیرید.', 'Blocked user message', '[]'),
('registration_pending_approval', '✅ پرداخت شما با موفقیت ثبت شد.\n\nلیگ: {league_name}\nنام: {player_name}\nمبلغ: {fee_formatted}\nشماره پیگیری: {ref_id}\n\nدرخواست شما در انتظار تأیید نهایی مدیر است.', 'Payment received, awaiting admin confirmation', '["league_name","player_name","fee_formatted","ref_id"]'),
('payment_cancelled', '⚠️ پرداخت لغو شد.\n\nمی‌توانید از منوی ربات دوباره درگاه پرداخت را انتخاب کنید.', 'Payment cancelled by user', '[]'),
('registration_approved', 'برای تکمیل ثبت‌نام در لیگ «{league_name}»، درگاه پرداخت را انتخاب کنید:', 'Payment gateway selection after signup', '["league_name","player_name","fee_formatted"]'),
('registration_rejected', '❌ متأسفانه ثبت‌نام شما در لیگ «{league_name}» رد شد.\n\n{reason_line}', 'Admin rejected registration', '["league_name","reason_line"]')
ON DUPLICATE KEY UPDATE text_key = text_key;

