-- Create payments table for Telegram Stars payments
CREATE TABLE IF NOT EXISTS payments (
    id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    user_id INT NOT NULL,
    order_id VARCHAR(255) NOT NULL UNIQUE COMMENT 'Unique order ID for Telegram invoice',
    stars_amount INT NOT NULL COMMENT 'Amount in Stars',
    tickets_amount BIGINT UNSIGNED NOT NULL COMMENT 'Tickets amount in bigint format (stars * 0.9 * 1,000,000)',
    status VARCHAR(20) NOT NULL DEFAULT 'PENDING' COMMENT 'PENDING, COMPLETED, FAILED, CANCELLED',
    telegram_payment_charge_id VARCHAR(255) NULL COMMENT 'Telegram payment charge ID',
    telegram_provider_payment_charge_id VARCHAR(255) NULL COMMENT 'Telegram provider payment charge ID',
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    completed_at TIMESTAMP NULL,
    INDEX idx_user_id (user_id),
    INDEX idx_order_id (order_id),
    INDEX idx_status (status),
    INDEX idx_created_at (created_at),
    FOREIGN KEY (user_id) REFERENCES db_users_a(id) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;




