import type { FeatureLockConfig } from "@/modules/communication/types";

/** Backend-active features (from /capabilities features[] + channel status). */
export const SMS_FEATURES = [
  "sms",
  "provider_framework",
  "communication_router",
  "template_engine",
  "dynamic_contact_sources",
  "queue_engine",
  "delivery_tracking",
  "otp",
  "webhooks",
  "failover",
  "circuit_breaker",
  "rate_limiting",
  "idempotency",
  "metrics",
] as const;

/** Future modules — always locked until backend registers capability. */
export const FUTURE_MODULE_REGISTRY: Record<string, FeatureLockConfig> = {
  email: {
    feature: "channel_email",
    title: "پلتفرم ایمیل",
    description: "ارسال ایمیل سازمانی با SMTP، قالب‌های HTML، پیگیری تحویل و failover.",
    phase: "Roadmap",
    bundle: "Communication Pro",
    capabilities: ["SMTP adapters", "HTML templates", "Bounce handling", "DKIM/SPF guides"],
    integrations: ["CRM", "Marketing", "Accounting"],
  },
  whatsapp: {
    feature: "channel_whatsapp",
    title: "واتساپ بیزینس",
    description: "پیام‌رسانی WhatsApp Cloud API با قالب‌های تأیید‌شده و webhook تحویل.",
    phase: "Roadmap",
    bundle: "Omnichannel Pack",
    capabilities: ["Template sync", "Read receipts", "Media messages", "Opt-in management"],
    integrations: ["CRM", "Support", "Campaigns"],
  },
  telegram: {
    feature: "channel_telegram",
    title: "تلگرام",
    description: "ربات تلگرام برای اعلان‌ها، OTP و پشتیبانی.",
    phase: "Roadmap",
    bundle: "Omnichannel Pack",
    capabilities: ["Bot API", "Inline keyboards", "Channel broadcasts"],
    integrations: ["Support", "Notifications"],
  },
  rubika: {
    feature: "channel_rubika",
    title: "روبیکا",
    description: "پیام‌رسانی اجتماعی بومی با adapter اختصاصی.",
    phase: "Roadmap",
    bundle: "Regional Pack",
    capabilities: ["Bot messaging", "Rich cards", "Delivery callbacks"],
    integrations: ["CRM", "Loyalty"],
  },
  push: {
    feature: "channel_push",
    title: "Push Notifications",
    description: "اعلان push موبایل و وب via FCM با ثبت توکن دستگاه.",
    phase: "Roadmap",
    bundle: "Mobile Pack",
    capabilities: ["FCM", "Device registry", "Silent push", "Topic subscriptions"],
    integrations: ["Mobile apps", "PWA"],
  },
  voice: {
    feature: "channel_voice",
    title: "تماس صوتی",
    description: "OTP و اعلان صوتی با gateway تلفنی.",
    phase: "Roadmap",
    bundle: "Voice Pack",
    capabilities: ["TTS", "Call status webhooks", "OTP voice path"],
    integrations: ["Identity", "Security"],
  },
  video: {
    feature: "channel_video",
    title: "تماس ویدیویی",
    description: "جلسات ویدیویی و تماس تصویری برای پشتیبانی.",
    phase: "Roadmap",
    bundle: "Enterprise",
    capabilities: ["WebRTC rooms", "Recording refs", "Scheduling"],
    integrations: ["CRM", "Support"],
  },
  live_chat: {
    feature: "live_chat",
    title: "Live Chat",
    description: "چت زنده وب‌سایت با routing به اپراتور.",
    phase: "Roadmap",
    bundle: "Support Pack",
    capabilities: ["Widget embed", "Agent queue", "Canned responses"],
    integrations: ["CRM", "Experience"],
  },
  omnichannel_inbox: {
    feature: "omnichannel_inbox",
    title: "صندوق ورودی Omnichannel",
    description: "تجمیع SMS، ایمیل، چت و شبکه‌های اجتماعی در یک inbox.",
    phase: "Roadmap",
    bundle: "Omnichannel Pack",
    capabilities: ["Unified threads", "Agent assignment", "SLA timers"],
    integrations: ["All channels", "CRM"],
  },
  marketing_automation: {
    feature: "marketing_automation",
    title: "Marketing Automation",
    description: "اتوماسیون کمپین چندمرحله‌ای با trigger و segment.",
    phase: "Roadmap",
    bundle: "Marketing Pro",
    capabilities: ["Drip campaigns", "A/B tests", "Segment builder"],
    integrations: ["CRM", "Loyalty", "Analytics"],
  },
  automation_triggers: {
    feature: "automation_triggers",
    title: "Automation Triggers",
    description: "تریگرهای رویداد-محور برای ارسال خودکار پیام.",
    phase: "Roadmap",
    bundle: "Automation",
    capabilities: ["Event hooks", "Conditions", "Delay steps"],
    integrations: ["All business modules"],
  },
  journey_builder: {
    feature: "journey_builder",
    title: "Journey Builder",
    description: "طراح بصری مسیر مشتری با شاخه و wait steps.",
    phase: "Roadmap",
    bundle: "Marketing Pro",
    capabilities: ["Visual canvas", "Branch logic", "Goal tracking"],
    integrations: ["CRM", "Loyalty"],
  },
  ai_campaigns: {
    feature: "ai_campaigns",
    title: "AI Campaigns",
    description: "پیشنهاد محتوا و زمان‌بندی هوشمند کمپین.",
    phase: "Roadmap",
    bundle: "AI Pack",
    capabilities: ["Content generation", "Send-time optimization", "Churn prediction"],
    integrations: ["AI Platform", "Analytics"],
  },
  webhook_center: {
    feature: "webhook_center",
    title: "Webhook Center",
    description: "مدیریت متمرکز webhookهای ورودی و خروجی.",
    phase: "Roadmap",
    bundle: "Developer",
    capabilities: ["Inbound/outbound", "Retry logs", "Signature rotation"],
    integrations: ["All providers"],
  },
  connectors: {
    feature: "third_party_connectors",
    title: "Third-party Connectors",
    description: "اتصال به سرویس‌های خارجی و marketplace adapters.",
    phase: "Roadmap",
    bundle: "Integrations",
    capabilities: ["Plugin registry", "OAuth flows", "Credential vault refs"],
    integrations: ["Zapier-style", "Custom REST"],
  },
  conversations: {
    feature: "customer_conversation_timeline",
    title: "Customer Conversation Timeline",
    description: "خط زمانی یکپارچه مکالمات مشتری across channels.",
    phase: "Roadmap",
    bundle: "CRM Plus",
    capabilities: ["360 timeline", "Agent notes", "Context handoff"],
    integrations: ["CRM", "Customer360"],
  },
  campaign_orchestrator: {
    feature: "campaign_orchestrator",
    title: "Campaign Orchestrator",
    description: "هماهنگی کمپین‌های چندکاناله با بودجه و cap.",
    phase: "Roadmap",
    bundle: "Marketing Pro",
    capabilities: ["Cross-channel caps", "Budget guard", "Orchestration rules"],
    integrations: ["SMS", "Email", "Push"],
  },
  notification_center: {
    feature: "notification_center",
    title: "Notification Center",
    description: "مرکز اعلان in-app و out-of-app برای tenant users.",
    phase: "Roadmap",
    bundle: "Platform",
    capabilities: ["In-app feed", "Preference center", "Digest mode"],
    integrations: ["All modules"],
  },
  template_categories: {
    feature: "template_categories",
    title: "دسته‌بندی قالب‌ها",
    description: "سازماندهی قالب‌ها در دسته‌های قابل جستجو.",
    phase: "Roadmap",
    bundle: "SMS Pro",
    capabilities: ["Category tree", "Bulk assign", "Permissions per category"],
    integrations: ["Templates"],
  },
  roles: {
    feature: "communication_roles",
    title: "نقش‌های ارتباطات",
    description: "مدیریت نقش اختصاصی Communication Platform.",
    phase: "Roadmap",
    bundle: "Enterprise",
    capabilities: ["Role templates", "Scoped permissions", "Audit"],
    integrations: ["Identity"],
  },
  audit: {
    feature: "communication_audit_ui",
    title: "ممیزی ارتباطات",
    description: "رابط کاربری جستجوی audit log (backend موجود — UI در roadmap).",
    phase: "Roadmap",
    bundle: "Enterprise",
    capabilities: ["Entity filter", "Export", "Retention policy"],
    integrations: ["Compliance"],
  },
  api_keys: {
    feature: "communication_api_keys",
    title: "کلیدهای API",
    description: "صدور و چرخش کلید API برای یکپارچه‌سازی سرویس-به-سرویس.",
    phase: "Roadmap",
    bundle: "Developer",
    capabilities: ["Scoped keys", "Rotation", "Usage metrics"],
    integrations: ["Core Identity"],
  },
  integrations_hub: {
    feature: "integrations_hub",
    title: "Integrations",
    description: "مرکز یکپارچه‌سازی با ماژول‌های TorbatYar.",
    phase: "Roadmap",
    bundle: "Platform",
    capabilities: ["Module connectors", "Event subscriptions", "Health checks"],
    integrations: ["CRM", "Loyalty", "Delivery", "Experience"],
  },
};

export function getFutureModule(key: string): FeatureLockConfig | undefined {
  return FUTURE_MODULE_REGISTRY[key];
}
