// Package i18n holds the user-facing strings in Persian (fa) and English
// (en). The bot picks the bundle based on the per-user language setting.
package i18n

// Lang is a supported UI language code.
type Lang string

const (
	Fa Lang = "fa"
	En Lang = "en"
)

// Normalize coerces arbitrary input into a supported Lang (default Fa).
func Normalize(s string) Lang {
	switch s {
	case "en", "EN", "En":
		return En
	default:
		return Fa
	}
}

// Bundle is the set of strings for one language.
type Bundle struct {
	Welcome          string
	Help             string
	NotAuthorized    string
	Banned           string
	WhitelistOnly    string
	ChooseLang       string
	LangSet          string
	StartCreate      string
	EnterPhone       string
	PhoneInvalid     string
	WaitingOTP       string
	EnterOTP         string
	InvalidOTP       string
	CreatingApp      string
	Success          string
	Failed           string
	MyKeys           string
	NoKeys           string
	LimitReached     string
	Cooldown         string
	Cancel           string
	Cancelled        string
	Back             string
	AdminPanel       string
	Stats            string
	BroadcastPrompt  string
	BroadcastSent    string
	BroadcastFailed  string
	BanUsage         string
	UnbanUsage       string
	UserNotFound     string
	BannedUser       string
	UnbannedUser     string
	Yes              string
	No               string
	Active           string
	Revoked          string
	ConfirmRevoke    string
	RevokedKey       string
	ProxiesHint      string
	Settings         string
	UnknownCommand   string
	KeysListHeader   string
}

var bundles = map[Lang]Bundle{
	Fa: {
		Welcome:         "👋 سلام %s!\n\nبه ربات سازنده API تلگرام خوش آمدید.\nبا این ربات می‌توانید <b>api_id</b> و <b>api_hash</b> رایگان و خودکار بسازید.",
		Help:            "📖 راهنما:\n\n/start — شروع\n/newkey — ساخت api_id و api_hash جدید\n/mykeys — کلیدهای ساخته‌شده‌ی شما\n/lang — تغییر زبان\n/help — این راهنما\n\n💡 برای ساخت کلید به شماره‌ای نیاز دارید که در تلگرام فعال باشد.",
		NotAuthorized:   "⛔ شما اجازه استفاده از این ربات را ندارید.",
		Banned:          "🚫 حساب شما توسط مدیر مسدود شده است.\nدر صورت اشتباه با پشتیبانی در تماس باشید.",
		WhitelistOnly:   "🔐 در حال حاضر ربات فقط برای کاربران مجاز فعال است.",
		ChooseLang:      "🌐 زبان ربات را انتخاب کنید:",
		LangSet:         "✅ زبان ربات به %s تغییر یافت.",
		StartCreate:     "🚀 آماده‌ایم تا یک کلید API جدید بسازیم.\n\nبرای ادامه، شماره موبایل خود را با کد کشور ارسال کنید (مثال: <code>989121234567</code>).",
		EnterPhone:      "📱 شماره موبایل خود را ارسال کنید (با کد کشور، بدون +):",
		PhoneInvalid:    "❌ شماره نامعتبر است. لطفاً فقط عدد با کد کشور ارسال کنید (مثال: <code>989121234567</code>).",
		WaitingOTP:      "📨 یک کد ورود به اکانت تلگرام این شماره ارسال شد.\n\nکد را به صورت یک پیام ارسال کنید.\n⚠️ کد ۲FA (رمز عبور ابری) نیست؛ کدی است که به اپ تلگرام شما می‌رسد.",
		EnterOTP:        "🔢 کد دریافتی را ارسال کنید:",
		InvalidOTP:      "❌ کد وارد شده نامعتبر بود یا منقضی شده است.\nدوباره تلاش کنید: /newkey",
		CreatingApp:     "⏳ در حال ساخت اپلیکیشن در my.telegram.org ...",
		Success:         "✅ کلید با موفقیت ساخته شد!\n\n<b>App title:</b> %s\n<b>API ID:</b> <code>%s</code>\n<b>API Hash:</b> <code>%s</code>\n\n🔑 این اطلاعات را در جای امن نگه دارید.",
		Failed:          "⚠️ ساخت کلید ناموفق بود:\n<code>%s</code>\n\nمی‌توانید دوباره تلاش کنید: /newkey",
		MyKeys:          "🗂 کلیدهای ساخته‌شده‌ی شما (%d):\n\n%s",
		NoKeys:          "🗂 شما هنوز کلندی نساخته‌اید.\nبا /newkey شروع کنید.",
		LimitReached:    "📊 سقف روزانه‌ی شما (%d کلید) تکمیل شده است.\nفردا دوباره تلاش کنید.",
		Cooldown:        "⏱ لطفاً %d ثانیه دیگر دوباره تلاش کنید.",
		Cancel:          "❌ لغو",
		Cancelled:       "عملیات لغو شد.",
		Back:            "↩️ بازگشت",
		AdminPanel:      "🛠 پنل مدیریت\nکاربران: %d | کلیدها: %d | کلیدهای امروز: %d | پراکسی فعال: %d",
		Stats:           "📊 آمار کلی\n\n👥 کاربران: %d\n🔑 کلیدها: %d\n📅 کلیدهای امروز: %d\n🌐 پراکسی‌ها: %d (فعال: %d)\n🚫 مسدودشده‌ها: %d",
		BroadcastPrompt: "📣 پیام همگانی:\nلطفاً متن پیام را ارسال کنید (یا /cancel برای لغو).",
		BroadcastSent:   "✅ پیام به %d کاربر ارسال شد (%d ناموفق).",
		BroadcastFailed: "❌ ارسال همگانی ناموفق بود: %s",
		BanUsage:        "استفاده: /ban <user_id>",
		UnbanUsage:      "استفاده: /unban <user_id>",
		UserNotFound:    "کاربر یافت نشد.",
		BannedUser:      "🚫 کاربر %d مسدود شد.",
		UnbannedUser:    "✅ کاربر %d از حالت مسدودی خارج شد.",
		Yes:             "بله",
		No:              "خیر",
		Active:          "فعال",
		Revoked:         "ابطال‌شده",
		ConfirmRevoke:   "آیا از ابطال این کلید مطمئنید؟",
		RevokedKey:      "✅ کلید ابطال شد.",
		ProxiesHint:     "🌐 مدیریت پراکسی‌ها از پنل وب انجام می‌شود:\n%s",
		Settings:        "⚙️ تنظیمات فعلی:\n\nزبان شما: %s\nسقف روزانه: %d کلید\nپراکسی فعال: %d",
		UnknownCommand:  "🤔 دستور نامشخص. /help را ببینید.",
		KeysListHeader:  "🗓 کلیدهای شما",
	},
	En: {
		Welcome:         "👋 Hi %s!\n\nWelcome to the Telegram API creator bot.\nGenerate free <b>api_id</b> and <b>api_hash</b> automatically.",
		Help:            "📖 Help:\n\n/start — start\n/newkey — create a new api_id and api_hash\n/mykeys — your created keys\n/lang — change language\n/help — this help\n\n💡 You need an active Telegram number to create keys.",
		NotAuthorized:   "⛔ You are not allowed to use this bot.",
		Banned:          "🚫 Your account has been banned by the admin.",
		WhitelistOnly:   "🔐 The bot is currently restricted to whitelisted users.",
		ChooseLang:      "🌐 Choose the bot language:",
		LangSet:         "✅ Bot language changed to %s.",
		StartCreate:     "🚀 Ready to create a new API key.\n\nSend your phone number with the country code (e.g. <code>989121234567</code>) to continue.",
		EnterPhone:      "📱 Send your phone number with the country code, no +:",
		PhoneInvalid:    "❌ Invalid number. Send digits only with the country code (e.g. <code>989121234567</code>).",
		WaitingOTP:      "📨 A login code was sent to the Telegram account of this number.\n\nSend the code as a message.\n⚠️ This is NOT your 2FA password; it's the code pushed to your Telegram app.",
		EnterOTP:        "🔢 Send the code you received:",
		InvalidOTP:      "❌ The code was invalid or expired.\nTry again: /newkey",
		CreatingApp:     "⏳ Creating the application on my.telegram.org ...",
		Success:         "✅ Key created successfully!\n\n<b>App title:</b> %s\n<b>API ID:</b> <code>%s</code>\n<b>API Hash:</b> <code>%s</code>\n\n🔑 Keep this information safe.",
		Failed:          "⚠️ Key creation failed:\n<code>%s</code>\n\nYou can try again: /newkey",
		MyKeys:          "🗂 Your created keys (%d):\n\n%s",
		NoKeys:          "🗂 You haven't created any key yet.\nStart with /newkey.",
		LimitReached:    "📊 Your daily limit (%d keys) is reached.\nTry again tomorrow.",
		Cooldown:        "⏱ Please try again in %d seconds.",
		Cancel:          "❌ Cancel",
		Cancelled:       "Operation cancelled.",
		Back:            "↩️ Back",
		AdminPanel:      "🛠 Admin panel\nUsers: %d | Keys: %d | Today: %d | Active proxies: %d",
		Stats:           "📊 Global stats\n\n👥 Users: %d\n🔑 Keys: %d\n📅 Today: %d\n🌐 Proxies: %d (active: %d)\n🚫 Banned: %d",
		BroadcastPrompt: "📣 Broadcast:\nSend the message text (or /cancel to abort).",
		BroadcastSent:   "✅ Message sent to %d users (%d failed).",
		BroadcastFailed: "❌ Broadcast failed: %s",
		BanUsage:        "Usage: /ban <user_id>",
		UnbanUsage:      "Usage: /unban <user_id>",
		UserNotFound:    "User not found.",
		BannedUser:      "🚫 User %d banned.",
		UnbannedUser:    "✅ User %d unbanned.",
		Yes:             "Yes",
		No:              "No",
		Active:          "active",
		Revoked:         "revoked",
		ConfirmRevoke:   "Are you sure you want to revoke this key?",
		RevokedKey:      "✅ Key revoked.",
		ProxiesHint:     "🌐 Proxies are managed from the web panel:\n%s",
		Settings:        "⚙️ Current settings:\n\nYour language: %s\nDaily limit: %d keys\nActive proxies: %d",
		UnknownCommand:  "🤔 Unknown command. See /help.",
		KeysListHeader:  "🗓 Your keys",
	},
}

// Get returns the bundle for the given language (falls back to Fa).
func Get(l Lang) Bundle {
	if b, ok := bundles[Normalize(string(l))]; ok {
		return b
	}
	return bundles[Fa]
}

// LangLabel returns a human-readable name for a Lang code.
func LangLabel(l Lang) string {
	switch Normalize(string(l)) {
	case En:
		return "English"
	default:
		return "فارسی"
	}
}
