from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import ContextTypes

from services.auth_service import is_admin
from services.vs_service import add_vs_package


async def tambah_vs_paket(
    update: Update,
    context: ContextTypes.DEFAULT_TYPE
):

    if not is_admin(update.effective_user.id):
        return

    text = " ".join(context.args)

    if "|" not in text:
        await update.message.reply_text(
            "Format:\n"
            "/vspaket NAMA_PAKET|HARGA"
        )
        return

    nama, harga = text.split("|", 1)

    target_admin = context.user_data.get(
    "vs_target_admin",
    update.effective_user.id
)

    add_vs_package(
        target_admin,
        nama.strip(),
        harga.strip()
    )

    await update.message.reply_text(
        f"✅ Paket '{nama}' berhasil ditambahkan",
        reply_markup=InlineKeyboardMarkup([[
            InlineKeyboardButton("⬅️ Kembali", callback_data="vs_manage")
        ]])
    )