"""
Pattern definitions and constants for target extraction
"""

EXPLICIT_ACTION_PHRASES = {
    "DOCUMENTATION_UPDATED": {
        "i have documented",
        "i've documented",
        "i have added notes",
        "i've added notes",
        "i logged this",
        "i have logged this",
        "added to the ticket",
        "updated the case notes",
    },
    "ACCOUNT_UPDATED": {
        "i have updated your account",
        "i've updated your account",
        "your account has been updated",
        "i changed your plan",
        "i have changed your settings",
    },
    "ESCALATION_CREATED": {
        "i'm escalating",
        "i am escalating",
        "i'll escalate",
        "i will escalate",
        "escalate this",
        "creating the escalation",
        "creating an escalation",
        "submit to escalation",
        "escalating this to",
        "escalate this directly",
        "open escalation case",
    },
    "REPLACEMENT_ORDERED": {
        "ship replacement",
        "send a replacement",
        "replacement order",
        "replacement will be shipped",
        "send you a new one",
        "ship a new one",
        "replacement should go out",
        "process replacement",
        "issue replacement",
        "replacement has been",
        "ordering a replacement",
    },
    "TRIAL_ACTIVATED": {
        "i'll activate your trial",
        "trial activated",
        "activated your trial",
        "trial has been activated",
        "started your trial",
        "your trial is now active",
        "enabled your trial",
        "activate a trial for you",
        "i can activate a trial",
        "activate a 14-day trial",
        "set you up with a trial",
        "activating a trial",
        "activate that for you",
        "i'll activate a",
    },
    "APPOINTMENT_SCHEDULED": {
        "i've scheduled an appointment",
        "appointment has been scheduled",
        "appointment has been booked",
        "booked an appointment",
        "scheduled a technician visit",
        "booked a technician",
        "appointment is confirmed",
        "appointment is set",
        "i've booked a",
        "i have scheduled an appointment",
    },
    "ACCOUNT_VERIFIED": {
        "verified your account",
        "i've verified your account",
        "your account has been verified",
        "verified your identity",
        "identity verified",
        "verification successful",
        "i have verified your",
        "account verified",
        "just need to verify your identity",
    },
    "REFUND_INITIATED": {
        "initiated a refund",
        "refund has been initiated",
        "processing your refund",
        "submitted a refund",
        "process a refund",
        "i'll process a refund",
        "issued a refund",
        "refund will be processed",
        "refund of",
        "issue a refund",
    },
}
TECHNICAL_ISSUE_MAP = {
    "OUTAGE": ["outage", "down", "offline", "multiple customers"],
    "PACKET_LOSS": ["packet loss", "degraded line"],
    "INTERMITTENT_CONNECTIVITY": ["keeps dropping", "intermittent"],
}
EXPLICIT_ONLY_ACTIONS = {
    "DOCUMENTATION_UPDATED",
    "ACCOUNT_UPDATED",
    "REQUEST_APPROVED",
    "ESCALATION_CREATED",
    "REPLACEMENT_ORDERED",
    "TRIAL_ACTIVATED",
    "ACCOUNT_VERIFIED",
    "REFUND_INITIATED",
    "APPOINTMENT_SCHEDULED",
    "SERVICE_CANCELLED",
    "RETENTION_OFFER",
}
TROUBLESHOOTING_ACTIONS = {
    "TROUBLESHOOTING_PERFORMED": {
        "ran a test",
        "reset",
        "rebooted",
        "cleared",
        "flushed",
        "performed",
        "applied fix",
    },
    "DIAGNOSTIC_PERFORMED": {
        "checked",
        "looked at",
        "can see",
        "reviewed logs",
        "i see",
        "pulled up",
        "ran diagnostics",
        "line test",
    },
}

ACTION_EVENT_MAP = {
    "VERIFY": "ACCOUNT_VERIFIED",
    "TROUBLESHOOT": "TROUBLESHOOT",
    "ESCALATE": "ESCALATION_CREATED",
    "REPLACE": "REPLACEMENT_ORDERED",
    "SCHEDULE": "APPOINTMENT_SCHEDULED",
    "UPDATE_INFO": "ACCOUNT_UPDATED",
    "CANCEL": "SERVICE_CANCELLED",
    "OFFER_DISCOUNT": "DISCOUNT_APPLIED",
    "APPROVE": "REQUEST_APPROVED",
    "DENY": "REQUEST_DENIED",
    "NOTIFY": "CUSTOMER_NOTIFIED",
    "DOCUMENT": "DOCUMENTATION_UPDATED",
    "ACTIVATE_TRIAL": "TRIAL_ACTIVATED",
    "REFUND": "REFUND_INITIATED",
    "FOLLOW_UP": "FOLLOWUP_SCHEDULED",
}

# Explicit phrase-matched agent actions (bypass keyword index, require exact phrase match)
EXPLICIT_AGENT_ACTION_PHRASES = {
    "ACCOUNT_LOOKUP": [
        "pulled up your account",
        "let me check your account",
        "looking at your account",
        "i have your account",
    ],
    "CASE_REVIEWED": [
        "reviewed your case",
        "looking at your case",
        "checked your case",
        "reviewed the case",
    ],
    "ORDER_STATUS_CHECKED": [
        "checked your order",
        "looking at your order",
        "i see your order",
        "checked the order status",
    ],
    "FOLLOWUP_SCHEDULED": [
        "i'll follow up",
        "follow up tomorrow",
        "personally follow up",
        "follow up with you",
    ],
    "IDENTITY_VERIFIED": [
        "verified your identity",
        "identity verified",
        "verification successful",
        "identity has been verified",
    ],
    "PROFILE_UPDATED": [
        "updated your account name",
        "changed your profile",
        "updated your profile",
        "name has been updated",
        "profile has been updated",
        "updated your name",
    ],
    "PRIORITY_DISPATCH_FLAGGED": [
        "flagged for same-day",
        "prioritize your order",
        "flagged it for",
        "priority dispatch",
    ],
    "LOGS_REVIEWED": [
        "reviewed the logs",
        "checked the logs",
        "looking at the logs",
        "reviewed your logs",
    ],
    "FEE_REVIEWED": [
        "reviewed the fee",
        "looked at the charge",
        "checked the fee",
        "reviewed the charge",
    ],
    "FEE_WAIVED": [
        "waived the fee",
        "removed the fee",
        "fee has been waived",
        "waive that fee",
        "waive it as a one-time courtesy",
        "reversed the charge",
        "reverse the charge",
        "i've just reversed",
        "reversed the fee",
        "can waive it",
        "waiving the fee",
        "i've reversed",
    ],
    "CREDIT_APPLIED": [
        "applied a credit",
        "credit has been applied",
        "credited your account",
        "applied the credit",
    ],
    "REFUND_INITIATED": [
        "initiated a refund",
        "refund has been initiated",
        "processing your refund",
        "submitted a refund",
        "process a refund",
        "i'll process a refund",
    ],
    "PASSWORD_RESET": [
        "reset your password",
        "password has been reset",
        "sent a reset link",
    ],
    "SERVICE_RESTORED": [
        "service has been restored",
        "restored your service",
        "service is back",
        "connection restored",
        "connection has been restored",
        "i'm now seeing the connection",
        "seeing the connection restored",
    ],
    "PLAN_UPGRADED": [
        "upgraded your plan",
        "plan has been upgraded",
        "upgrade is complete",
    ],
    "SUBSCRIPTION_PAUSED": [
        "paused your subscription",
        "subscription has been paused",
        "put your subscription on hold",
        "i'll pause your subscription",
        "pause your subscription",
        "pausing your subscription",
        "subscription will be paused",
    ],
    "SERVICE_CANCELLED": {
        "cancelled your subscription",
        "subscription has been cancelled",
        "subscription is now cancelled",
        "i've cancelled your",
        "i have cancelled",
        "cancellation is complete",
        "cancellation has been processed",
    },
    "RETENTION_OFFER": [
        "before i process it",
        "before i cancel",
        "i want to mention we offer",
        "we offer a pause option",
        "offer a pause option",
        "offer you a pause",
        "you can freeze your subscription",
        "freeze your subscription",
        "instead of canceling",
        "instead of cancelling",
        "as an alternative to cancellation",
        "as an alternative to canceling",
        "consider pausing",
        "option to pause",
        "you have the option to pause",
        "offer you an alternative",
    ],
    "DUPLICATE_PAYMENT_CONFIRMED": [
        "confirmed the duplicate",
        "duplicate payment confirmed",
        "can see the duplicate",
        "i can confirm the duplicate",
    ],
    "FEATURES_EXPLAINED": [
        "let me explain the features",
        "the plan includes",
        "you'll get access to",
        "comes with",
        "includes the following",
    ],
    "PRICING_EXPLAINED": [
        "the pricing is",
        "it costs",
        "the price is",
        "monthly fee is",
        "costs per month",
    ],
}
ISSUE_CONFIRMATION_MAP = {
    "DUPLICATE_PAYMENT_CONFIRMED": {
        "duplicate",
        "processed twice",
        "double charged",
        "two charges",
    }
}
SUPPORTED_ACTION_TYPES = {
    "REFUND",
    "CREDIT",
    "TROUBLESHOOT",
    "ESCALATE",
    "REPLACE",
    "CHARGE",
    "PAYMENT",
}

ACTION_COMPLETION_KEYWORDS = {
    "submitted",
    "processed",
    "completed",
    "filed",
    "applied",
    "issued",
    "sent",
    "done",
}

ACTION_COMPLETION_PHRASES = {
    "just submitted",
    "just processed",
    "already submitted",
    "already processed",
}

ACTION_NOW_PATTERNS = [
    r"(i('|’)ve|i have) (just )?(submitted|processed|filed)\b",
    r"i('?m| am) (processing|submitting|filing) (it|the|that)? (now)?\b",
]

POSITIVE_CUSTOMER_CONFIRMATIONS = {
    "perfect",
    "great",
    "thank",
    "got it",
    "received",
    "appreciate",
}

AGENT_CONFIRMATION_PHRASES = {
    "all set",
    "you're all set",
    "that's done",
    "completed",
}

RESOLUTION_KEYWORDS = {
    # Future/conditional phrases must come before "resolved"/"fixed" so they
    # take priority when both appear in the same sentence
    # (e.g. "expected to be resolved by this evening").
    "PENDING": {
        "expected to be resolved",
        "expected to be fixed",
        "will be resolved by",
        "should be resolved by",
        "expected to resolve",
        "technicians have been dispatched",
        "dispatched to resolve",
    },
    "RESOLVED": {"resolved", "fixed", "solved", "approved", "payout"},
    "ESCALATED": {"escalate", "supervisor", "transfer"},
    "PENDING_REPLACEMENT": {"replace", "replacement", "exchange"},
}

BILLING_CAUSE_KEYWORDS = {
    "DUPLICATE_PROCESSING": {"duplicate", "processed twice", "retried"},
    "DOUBLE_BILLING": {"double billing"},
    "PRORATION_CONFUSION": {"proration", "prorated"},
    "SYSTEM_ERROR": {"error", "mistake"},
    "MID_CYCLE_UPGRADE": {"upgrade"},
    "MID_CYCLE_DOWNGRADE": {"downgrade"},
    "BILLING_OVERLAP": {"overlap"},
}

ISSUE_TYPE_KEYWORDS = {
    "BILLING_DISPUTE": {"bill", "charge", "refund", "charged"},
    "CONNECTIVITY": {"internet", "connection", "wifi"},
    "PERFORMANCE": {"slow", "speed"},
    "ACCOUNT_UPDATE": {
        "update my",
        "change my name",
        "profile update",
        "locked out",
        "update my name",
    },
    "REFUND_ISSUE": {
        "refund",
        "money back",
        "reimburse",
        "hasn't come through",
        "refund status",
    },
    "DELIVERY_ISSUE": {
        "delivery",
        "shipped",
        "tracking number",
        "track my order",
        "shipment tracking",
        "haven't received",
        "where is my order",
        "where is my package",
        "package hasn't arrived",
    },
    "SECURITY_ISSUE": {
        "unauthorized",
        "hacked",
        "suspicious",
        "someone logged",
        "someone accessed",
        "someone signed into",
        "signed in from",
        "wasn't me",
        "login alert",
        "unexpected login",
        "login from another",
    },
    "SUBSCRIPTION_ISSUE": {
        "cancel subscription",
        "pause",
        "downgrade",
        "plan change",
        "cancel my subscription",
    },
    "PRODUCT_ISSUE": {"defective", "not working", "broken", "installation"},
    "OUTAGE": {"outage", "down", "offline", "service disruption", "service is down"},
    "SYNC_ISSUE": {"sync", "syncing", "not syncing", "sync error"},
    "DUPLICATE_CHARGE": {
        "duplicate charge",
        "charged twice",
        "double charged",
        "duplicate payment",
    },
    "LOGIN_FAILURE": {
        "can't log in",
        "locked out",
        "can't access my account",
        "login issue",
    },
    "PLAN_UPGRADE": {
        "upgrade",
        "upgrading",
        "what features",
        "upgrade my plan",
        "upgrade to",
        "considering upgrading",
    },
    "FEE_DISPUTE": {"charged a fee", "service fee", "late fee", "unexpected fee"},
}

SEVERITY_KEYWORDS = {
    "HIGH": {
        "critical",
        "urgent",
        "emergency",
        "not working at all",
        "can't work",
    },
    "MEDIUM": {
        "frustrated",
        "annoying",
        "need it for work",
        "important",
    },
}


TECHNICAL_CONCEPTS = [
    "data structures",
    "algorithms",
    "computational complexity",
    "operating systems",
    "virtual memory",
    "concurrency",
    "multithreading",
    "parallel computing",
    "distributed systems",
    "load balancing",
    "event-driven architecture",
    "ip",
    "udp",
    "icmp",
    "ssh",
    "ftp",
    "smtp",
    "snmp",
    "websockets",
    "vpn",
    "cdn",
    "proxy servers",
    "firewalls",
    "nat",
    "bgp",
    "relational databases",
    "document databases",
    "graph databases",
    "time-series databases",
    "indexing",
    "query optimization",
    "acid",
    "event sourcing",
    "data warehousing",
    "etl",
    "data lakes",
    "caching",
    "redis",
    "elasticsearch",
    "object-oriented programming",
    "functional programming",
    "test-driven development",
    "design patterns",
    "dependency injection",
    "continuous integration",
    "continuous deployment",
    "version control",
    "git",
    "monolith",
    "microfrontends",
    "domain-driven design",
    "clean architecture",
    "infrastructure as code",
    "terraform",
    "ansible",
    "jenkins",
    "cicd pipelines",
    "monitoring",
    "observability",
    "logging",
    "prometheus",
    "grafana",
    "load testing",
    "chaos engineering",
    "reinforcement learning",
    "computer vision",
    "natural language processing",
    "generative ai",
    "transformers",
    "autoencoders",
    "feature engineering",
    "data preprocessing",
    "model deployment",
    "mlops",
    "vector databases",
    "encryption",
    "hashing",
    "ssl",
    "tls",
    "oauth",
    "jwt",
    "zero trust architecture",
    "penetration testing",
    "vulnerability scanning",
    "access control",
    "iam",
    "next.js",
    "svelte",
    "astro",
    "webassembly",
    "typescript",
    "tailwind css",
    "progressive web apps",
    "responsive design",
    "web performance optimization",
    "grpc",
    "openapi",
    "soap",
    "rate limiting",
    "api gateway",
    "message queues",
    "rabbitmq",
    "kafka",
    "event-driven systems",
    "background jobs",
    "webhooks",
    "ecs",
    "eks",
    "lambda",
    "cloud run",
    "app engine",
    "cloudflare workers",
    "service mesh",
    "istio",
    "helm",
    "container orchestration",
    "edge computing",
    "fog computing",
    "5g",
    "iot",
    "ar",
    "vr",
    "xr",
    "federated learning",
    "quantum encryption",
    "digital twins",
    "neuromorphic computing",
    "go",
    "rust",
    "swift",
    "kotlin",
    "scala",
    "r",
    "bash",
    "c",
    "c++",
    "java",
    "ruby",
    "php",
    "dart",
    "flutter",
    "swiftui",
    "big data",
    "hadoop",
    "spark",
    "kafka streams",
    "flink",
    "databricks",
    "data pipelines",
    "real-time analytics",
    "business intelligence",
    "power bi",
    "tableau",
]

CX_TECHNICAL_CONCEPTS = [
    "customer experience",
    "customer journey",
    "customer satisfaction",
    "customer retention",
    "customer loyalty",
    "customer lifetime value",
    "net promoter score",
    "nps",
    "csat",
    "ces",
    "customer effort score",
    "churn rate",
    "voice of the customer",
    "voc",
    "ticketing system",
    "helpdesk software",
    "sla",
    "first response time",
    "average handle time",
    "aht",
    "first call resolution",
    "fcr",
    "resolution time",
    "queue management",
    "escalation management",
    "after call work",
    "acw",
    "wrap-up codes",
    "call disposition",
    "call scripts",
    "knowledge base",
    "faq automation",
    "self-service portal",
    "omnichannel support",
    "multichannel support",
    "call handling",
    "inbound calls",
    "outbound calls",
    "call queue",
    "warm transfer",
    "cold transfer",
    "call escalation",
    "ticket creation",
    "voice support",
    "email support",
    "chat support",
    "live chat",
    "social media support",
    "whatsapp support",
    "sms support",
    "video support",
    "blended agents",
    "channel switching",
    "co-browsing",
    "screen sharing",
    "crm",
    "agent workspace",
    "unified agent desktop",
    "zendesk",
    "freshdesk",
    "intercom",
    "salesforce service cloud",
    "hubspot service hub",
    "helpscout",
    "genesys",
    "genesys cloud",
    "twilio flex",
    "nice incontact",
    "five9",
    "avaya",
    "amazon connect",
    "ccaas",
    "frontapp",
    "aircall",
    "qualtrics",
    "medallia",
    "chatbots",
    "voicebots",
    "virtual assistants",
    "conversational ai",
    "natural language processing",
    "nlp routing",
    "sentiment analysis",
    "intent detection",
    "speech analytics",
    "voice recognition",
    "predictive analytics",
    "ai routing",
    "automated responses",
    "co-pilot ai",
    "agent assist ai",
    "automated workflows",
    "rpa",
    "bot handoff",
    "queue prioritization",
    "call routing",
    "skill-based routing",
    "emotion detection",
    "next best action",
    "customer data platform",
    "cdp",
    "crm integration",
    "data integration",
    "real-time analytics",
    "dashboards",
    "reporting automation",
    "cohort analysis",
    "text analytics",
    "journey analytics",
    "feedback analytics",
    "customer segmentation",
    "agent performance dashboard",
    "leaderboards",
    "kpi tracking",
    "api integration",
    "webhooks",
    "bi tools integration",
    "single sign-on",
    "sso",
    "oauth",
    "rest api",
    "graphql api",
    "workflow automation",
    "ifttt",
    "zapier",
    "data synchronization",
    "real-time data fetch",
    "user experience",
    "user interface",
    "ux design",
    "ui design",
    "personalization",
    "customer onboarding",
    "journey mapping",
    "heatmaps",
    "a/b testing",
    "conversion optimization",
    "behavioral analytics",
    "user feedback loops",
    "context-aware responses",
    "contact center as a service",
    "ivr",
    "interactive voice response",
    "auto dialer",
    "predictive dialer",
    "automatic call distributor",
    "acd",
    "call recording",
    "screen recording",
    "call monitoring",
    "live coaching",
    "speech-to-text",
    "cloud telephony",
    "call routing",
    "ivr menu design",
    "real-time monitoring",
    "agent dashboards",
    "softphone",
    "headset integration",
    "voip",
    "vpn connection",
    "latency monitoring",
    "system uptime",
    "network quality metrics",
    "call latency",
    "packet loss",
    "webrtc",
    "browser-based contact center",
    "thin client environments",
    "gdpr",
    "ccpa",
    "data privacy",
    "pii masking",
    "data redaction",
    "pci compliance",
    "security compliance",
    "access control",
    "encryption",
    "audit logs",
    "role-based permissions",
    "secure payment capture",
    "identity verification",
    "call authentication",
    "voice biometrics",
    "knowledge-based authentication",
    "session recording consent",
    "two-factor authentication",
    "e-learning modules",
    "microlearning",
    "gamification",
    "coaching sessions",
    "agent onboarding",
    "call simulations",
    "ai feedback",
    "training analytics",
    "knowledge suggestions",
    "contextual knowledge surfacing",
    "real-time assist prompts",
    "virtual training environments",
    "customer profile",
    "interaction history",
    "case notes",
    "customer sentiment",
    "customer intent",
    "journey orchestration",
    "proactive support",
    "predictive support",
    "hyper-personalization",
    "contextual engagement",
    "customer digital twin",
    "emotion ai",
    "real-time translation",
    "voice biometrics",
    "augmented reality support",
    "self-healing systems",
    "recommendation engine",
    "agent sentiment tracking",
    "real-time transcription",
    "automated note taking",
    "proactive engagement prompts",
]

# Compound phrase mappings
COMPOUND_PHRASES = {
    "customer support": "TICKET",
    "support ticket": "TICKET",
    "email message": "EMAIL",
    "chat thread_encoder": "TRANSCRIPT",
    "phone call": "CALL",
    "source code": "CODE",
}

# Type keyword mappings
TYPE_KEYWORDS = {
    "call": "CALL",
    "meeting": "MEETING",
    "chat": "CHAT",
    "conversation": "CONVERSATION",
    "report": "REPORT",
    "article": "ARTICLE",
}

CONTEXT_KEYWORDS = {
    "customer": "CUSTOMER",
    "support": "SUPPORT",
    "sales": "SALES",
    "technical": "TECHNICAL",
}

NER_DOMAIN_PATTERNS = {
    "ACCOUNT_NUMBER": [
        r"\b[A-Z]{2,4}\d{6,12}\b",
        r"\baccount(?: number)?[:\s#]+([A-Z0-9-]+)\b",
        r"\bacct[:\s#]+([A-Z0-9-]+)\b",
        r"\bprofile[:\s#]+([A-Z0-9-]+)\b",
        r"\bID[:\s#]+([A-Z0-9-]+)\b",
    ],
    "ORDER_NUMBER": [
        r"\border(?: number)?[:\s#]+([A-Z0-9-]+)\b",
        r"\bORD-?\d{5,12}\b",
        r"\bPO-?\d{5,12}\b",
        r"\bSO-?\d{5,12}\b",
    ],
    "TRACKING_NUMBER": [
        r"\b([A-Z]{2}-\d{7,12})\b",
        r"\bTRK\d{8,14}\b",
        r"\btracking(?: number)?[:\s#]+([A-Z0-9-]+)\b",
        r"\b([A-Z0-9]{8,14})\b(?=.*\b(shipped|delivered|courier|carrier)\b)",
        r"\b([A-Z]{2}\d{9}[A-Z]{2})\b",
    ],
    "CLAIM_NUMBER": [
        r"\b[A-Z]{2,4}-CLA-\d{5,10}\b",
        r"\bCLM-?\d{5,10}\b",
        r"\bclaim(?: number)?[:\s#]+([A-Z0-9-]+)\b",
        r"\bwarranty[:\s#]+([A-Z0-9-]+)\b",
    ],
    "TICKET_NUMBER": [
        r"\bTIC?-?\d{5,12}\b",
        r"\bTK-?\d{5,12}\b",
        r"\bticket(?: number)?[:\s#]+([A-Z0-9-]+)\b",
        r"\bSR-?\d{5,12}\b",
        r"\bINC-?\d{5,12}\b",
    ],
    "CASE_NUMBER": [
        r"\bCASE-?\d{5,12}\b",
        r"\bCS-?\d{5,12}\b",
        r"\bcase(?: number)?[:\s#]+([A-Z0-9-]+)\b",
        r"\bCSE-?\d{5,12}\b",
        r"\bcase\s*(?:number)?\s*(?:is)?\s*(\d{4,})\b",
    ],
    "ESCALATION_ID": [
        r"\bESC-?\d{4,10}\b",
        r"\bTEC-?\d{4,10}\b",
        r"\bescalation[:\s#]+([A-Z0-9-]+)\b",
    ],
    "VERIFICATION_CODE": [
        r"\b(?:code|verification)\s*(?:is|:)?\s*(\d{4,8})\b",
        r"\bverification\s+code\s*(?:is|:)?\s*(\d{4,8})\b",
    ],
    "PRODUCT_MODEL": [
        r"\b([A-Z]{2,4}-\d{3,5}[A-Z]?)\b",
        r"\b([A-Z0-9]{3,10}-[A-Z0-9]{2,6})\b",
        r"\b([A-Z]{3}\d{3,5})\b",
        r"\bmodel(?: number)?[:\s#]+([A-Z0-9-]+)\b",
        r"\bSKU[:\s#]+([A-Z0-9-]+)\b",
    ],
    "PACKAGE_ID": [
        r"\bPKG-?\d{6,12}\b",
        r"\bpackage(?: id)?[:\s#]+([A-Z0-9-]+)\b",
        r"\bparcel[:\s#]+([A-Z0-9-]+)\b",
    ],
    "EMAIL": [
        r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b",
    ],
    "PHONE_NUMBER": [
        r"\b\+?\d{1,3}[-\s]?\(?\d{2,4}\)?[-\s]?\d{3}[-\s]?\d{3,5}\b",
        r"\b\d{10}\b",
    ],
    "INVOICE_NUMBER": [
        r"\bINV-?\d{5,12}\b",
        r"\binvoice[:\s#]+([A-Z0-9-]+)\b",
        r"\breceipt[:\s#]+([A-Z0-9-]+)\b",
        r"\btxn[:\s#]+([A-Z0-9-]+)\b",
    ],
    "SUBSCRIPTION_ID": [
        r"\bSUB-?\d{6,12}\b",
        r"\bsubscription[:\s#]+([A-Z0-9-]+)\b",
        r"\bplan[:\s#]+([A-Z0-9-]+)\b",
    ],
    "SERIAL_NUMBER": [
        r"\bSN[:\s#-]?([A-Z0-9]{6,20})\b",
        r"\bserial[:\s#]+([A-Z0-9-]{6,20})\b",
        r"\bIMEI[:\s#-]?(\d{14,16})\b",
        r"\bMAC[:\s#-]?([A-F0-9:]{12,17})\b",
    ],
    "POLICY_NUMBER": [
        r"\bPOL-?\d{6,12}\b",
        r"\bpolicy[:\s#]+([A-Z0-9-]+)\b",
    ],
    "MEMBER_ID": [
        r"\bMEM-?\d{5,12}\b",
        r"\bmember(?: id)?[:\s#]+([A-Z0-9-]+)\b",
        r"\bloyalty[:\s#]+([A-Z0-9-]+)\b",
    ],
    "DEVICE_ID": [
        r"\bDEV-?\d{6,12}\b",
        r"\bdevice(?: id)?[:\s#]+([A-Z0-9-]+)\b",
        r"\brouter[:\s#]+([A-Z0-9-]+)\b",
    ],
}

EMOTION_KEYWORDS = {
    "FRUSTRATED": {
        "keywords": [
            "frustrating",
            "frustrated",
            "annoying",
            "annoyed",
            "irritated",
            "fed up",
            "tired of this",
            "sick of",
            "can’t deal",
            "bothered",
            "called three times",
            "called multiple times",
            "nothing’s changed",
            "nothing has changed",
            "every agent keeps",
            "keeps saying it’s being worked on",
        ],
        "intensity": 0.7,
    },
    "ANGRY": {
        "keywords": [
            "angry",
            "furious",
            "mad",
            "outraged",
            "livid",
            "enraged",
            "infuriated",
            "hate this",
            "unacceptable",
            "ridiculous",
            "furious about",
        ],
        "intensity": 0.9,
    },
    "DISAPPOINTED": {
        "keywords": [
            "disappointed",
            "let down",
            "expected better",
            "not happy",
            "unsatisfied",
            "underwhelmed",
            "bummed",
            "disheartening",
            "poor experience",
        ],
        "intensity": 0.7,
    },
    "WORRIED": {
        "keywords": [
            "worried",
            "concerned",
            "anxious",
            "nervous",
            "uneasy",
            "afraid",
            "scared",
            "fearful",
            "uncertain",
            "unsure",
            "stressed about",
        ],
        "intensity": 0.6,
    },
    "CONFUSED": {
        "keywords": [
            "confused",
            "unclear",
            "don’t understand",
            "not sure",
            "lost",
            "bewildered",
            "unsure",
            "don’t get it",
            "need clarification",
            "mixed up",
        ],
        "intensity": 0.5,
    },
    "GRATEFUL": {
        "keywords": [
            "thank",
            "thanks",
            "thankful",
            "appreciate",
            "grateful",
            "means a lot",
            "really helpful",
            "much obliged",
            "so kind",
            "great support",
        ],
        "intensity": 0.6,
    },
    "SATISFIED": {
        "keywords": [
            "satisfied",
            "happy",
            "pleased",
            "great",
            "perfect",
            "wonderful",
            "excellent",
            "awesome",
            "amazing",
            "fantastic",
            "love it",
            "delighted",
        ],
        "intensity": 0.8,
    },
    "RELIEVED": {
        "keywords": [
            "relieved",
            "finally",
            "good to know",
            "glad it’s fixed",
            "that helps",
            "phew",
            "thank goodness",
            "much better now",
        ],
        "intensity": 0.6,
    },
    "IMPATIENT": {
        "keywords": [
            "waiting too long",
            "still waiting",
            "hurry up",
            "been waiting",
            "slow response",
            "why is this taking",
            "taking forever",
            "long time",
        ],
        "intensity": 0.65,
    },
    "HOPEFUL": {
        "keywords": [
            "hopeful",
            "optimistic",
            "looking forward",
            "expecting",
            "believe it’ll work",
            "trust it’ll be fine",
            "can’t wait",
            "excited to see",
        ],
        "intensity": 0.5,
    },
    "CALM": {
        "keywords": [
            "calm",
            "relaxed",
            "fine",
            "no rush",
            "take your time",
            "no worries",
            "it’s okay",
            "that’s alright",
        ],
        "intensity": 0.4,
    },
    "APOLOGETIC": {
        "keywords": [
            "sorry",
            "apologize",
            "my bad",
            "forgive me",
            "I didn’t mean to",
            "regret that",
            "please excuse",
            "didn’t realize",
            "won’t happen again",
        ],
        "intensity": 0.5,
    },
    "GRATEFUL_POSITIVE": {
        "keywords": [
            "thank you so much",
            "really appreciate it",
            "you’ve been amazing",
            "incredible help",
            "couldn’t have done it without you",
        ],
        "intensity": 0.7,
    },
    "RESENTFUL": {
        "keywords": [
            "resent",
            "fed up with",
            "done with this",
            "sick of dealing with",
            "can’t stand",
            "this always happens",
            "same issue again",
            "every time",
        ],
        "intensity": 0.75,
    },
    "SURPRISED": {
        "keywords": [
            "surprised",
            "shocked",
            "didn’t expect",
            "wow",
            "unbelievable",
            "didn’t think that would happen",
        ],
        "intensity": 0.6,
    },
    "APATHETIC": {
        "keywords": [
            "whatever",
            "doesn't matter",
            "I don't care",
            "meh",
            "it's fine",
            "not a big deal",
            "whatever you say",
        ],
        "intensity": 0.3,
    },
    "CURIOUS": {
        "keywords": [
            "curious",
            "wondering",
            "interested",
            "what about",
            "tell me more",
            "i'd like to know",
        ],
        "intensity": 0.4,
    },
    "ALARMED": {
        "keywords": [
            "alarmed",
            "panicked",
            "someone accessed",
            "unauthorized",
            "scared",
            "terrified",
        ],
        "intensity": 0.8,
    },
    "REASSURED": {
        "keywords": [
            "reassured",
            "feel better",
            "that's good to know",
            "puts my mind at ease",
            "good to hear",
            "makes me feel better",
        ],
        "intensity": 0.5,
    },
}

DAY_NAMES = {
    "monday": "MON",
    "tuesday": "TUE",
    "wednesday": "WED",
    "thursday": "THU",
    "friday": "FRI",
    "saturday": "SAT",
    "sunday": "SUN",
}

WORD_TO_NUM = {
    "one": 1,
    "two": 2,
    "three": 3,
    "four": 4,
    "five": 5,
    "six": 6,
    "seven": 7,
    "couple": 2,
    "a couple": 2,
    "few": 3,
    "a few": 3,
}

DAY_ORDER = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"]

NER_ADDRESS_ABBREVIATIONS = {
    "Street": "St",
    "Avenue": "Ave",
    "Road": "Rd",
    "Drive": "Dr",
    "Lane": "Ln",
    "Boulevard": "Blvd",
    "Court": "Ct",
    "Place": "Pl",
}

SYSTEM_ACTION_KEYWORDS = {
    "PAYMENT_RETRY_DETECTED": [
        "payment retry",
        "auto-retry",
        "automatic retry",
        "system retried",
    ],
    "AUTO_ESCALATION_TRIGGERED": [
        "auto-escalated",
        "automatically escalated",
        "system escalated",
    ],
    "SLA_BREACH_DETECTED": [
        "sla breach",
        "sla violation",
        "exceeded sla",
    ],
    "FRAUD_ALERT_TRIGGERED": [
        "fraud alert",
        "fraud detected",
        "suspicious activity",
    ],
    "ACCOUNT_AUTO_LOCKED": [
        "account automatically locked",
        "auto-locked",
        "system locked",
    ],
    "NOTIFICATION_SENT": [
        "notification sent",
        "automated email",
        "system notification",
    ],
}

ISSUE_TO_INTENT = {
    "BILLING_DISPUTE": "REPORT_BILLING_ISSUE",
    "DUPLICATE_CHARGE": "REPORT_DUPLICATE_CHARGE",
    "PAYMENT_FAILED": "REPORT_PAYMENT_FAILURE",
    "MISSING_REFUND": "REQUEST_REFUND_STATUS",
    "REFUND_DELAY": "REQUEST_REFUND_STATUS",
    "REFUND_REQUEST": "REQUEST_REFUND",
    "UNEXPECTED_CHARGE": "REPORT_UNEXPECTED_CHARGE",
    "OVERCHARGE": "REPORT_OVERCHARGE",
    "LOGIN_FAILURE": "REPORT_LOGIN_ISSUE",
    "AUTHENTICATION_ERROR": "REPORT_AUTH_ERROR",
    "ACCOUNT_LOCKED": "ACCOUNT_UNLOCK",
    "ACCOUNT_HACKED": "REPORT_SECURITY_BREACH",
    "INTERNET_OUTAGE": "REPORT_OUTAGE",
    "SLOW_INTERNET": "REPORT_SLOW_PERFORMANCE",
    "SERVER_DOWN": "REPORT_OUTAGE",
    "CONNECTIVITY": "REPORT_CONNECTIVITY_ISSUE",
    "WIFI_ISSUE": "REPORT_CONNECTIVITY_ISSUE",
    "DELIVERY_DELAY": "REPORT_DELIVERY_DELAY",
    "LOST_PACKAGE": "REPORT_LOST_PACKAGE",
    "DAMAGED_PACKAGE": "REPORT_DAMAGED_ITEM",
    "WRONG_ITEM": "REPORT_WRONG_ITEM",
    "SUBSCRIPTION_CANCELLATION": "CANCEL_SUBSCRIPTION",
    "PLAN_UPGRADE": "REQUEST_PLAN_CHANGE",
    "PLAN_DOWNGRADE": "REQUEST_PLAN_CHANGE",
    "RETURN_REQUEST": "REQUEST_RETURN",
    "EXCHANGE_REQUEST": "REQUEST_EXCHANGE",
    "ORDER_CANCELLATION": "CANCEL_ORDER",
    "PRODUCT_DEFECT": "REPORT_DEFECTIVE_PRODUCT",
    "FEATURE_NOT_WORKING": "FEATURE_INQUIRY",
    "PROFILE_UPDATE": "REQUEST_PROFILE_UPDATE",
    "DATA_PRIVACY_REQUEST": "REQUEST_DATA_DELETION",
    "ESCALATION_REQUEST": "REQUEST_ESCALATION",
    "APPOINTMENT_RESCHEDULE": "CANCEL_BOOKING",
    "APP_CRASH": "REPORT_APP_ISSUE",
    "TRACKING_ISSUE": "REQUEST_TRACKING_UPDATE",
    "INVOICE_REQUEST": "REQUEST_INVOICE",
    "CREDIT_CARD_UPDATE": "REQUEST_PAYMENT_UPDATE",
    "SYNC_ISSUE": "REPORT_SYNC_FAILURE",
    "FEE_DISPUTE": "DISPUTE_SERVICE_FEE",
    "PLAN_UPGRADE": "REQUEST_PLAN_UPGRADE",
    "SUBSCRIPTION_ISSUE": "REQUEST_CANCELLATION",
    "SECURITY_ISSUE": "REPORT_UNAUTHORIZED_LOGIN",
}
CUSTOMER_INTENT_KEYWORDS = {
    "REQUEST_PROFILE_UPDATE": [
        "i'd like to change",
        "update my",
        "change my name",
        "change my address",
        "update my name",
        "change my email",
    ],
    "REQUEST_REFUND_STATUS": [
        "when will my refund",
        "hasn't come through",
        "refund status",
        "where is my refund",
        "still waiting for my refund",
        "been waiting for a refund",
    ],
    "FOLLOWUP_REPLACEMENT_STATUS": [
        "replacement",
        "haven't received",
        "where is my replacement",
        "replacement status",
        "follow up on replacement",
    ],
    "REPORT_UNAUTHORIZED_LOGIN": [
        "unauthorized",
        "someone logged in",
        "someone accessed",
        "someone signed into",
        "signed into my account from",
        "wasn't me",
        "login alert",
        "unexpected login alert",
        "login from another",
        "signed in from",
        "hacked",
        "suspicious activity",
        "didn't authorize",
    ],
    "REQUEST_CANCELLATION": [
        "cancel",
        "cancel my subscription",
        "pause my subscription",
        "want to cancel",
        "stop my subscription",
    ],
    "REQUEST_PLAN_UPGRADE": [
        "upgrade my plan",
        "switch to premium",
        "move to a higher plan",
        "upgrade to",
        "considering upgrading",
        "want to upgrade",
        "looking to upgrade",
        "upgrade my subscription",
    ],
    "EVALUATE_PLAN_UPGRADE": [
        "what features",
        "what does the plan include",
        "what's included in",
        "curious about the features",
        "wanted to know if it includes",
        "does it include",
        "what analytics",
        "what analytics features",
        "plan includes",
    ],
    "REQUEST_TRIAL": [
        "trial",
        "free trial",
        "try it out",
        "try the plan",
        "test it",
        "14-day trial",
        "start a trial",
    ],
    "REPORT_LOGIN_FAILURE": [
        "can't log in",
        "locked out",
        "can't access my account",
        "login issue",
        "unable to sign in",
    ],
    "REPORT_SERVICE_OUTAGE": [
        "outage",
        "service is down",
        "not working at all",
        "internet is out",
        "service outage",
        "completely down",
    ],
    "REPORT_SYNC_FAILURE": [
        "not syncing",
        "sync error",
        "sync issue",
        "won't sync",
        "syncing problem",
        "files aren't updating",
        "files not updating",
        "not updating on my",
        "cloud storage syncing",
        "data not syncing",
        "syncing correctly",
        "syncing issues",
    ],
    "REPORT_INSTALLATION_ERROR": [
        "installation error",
        "can't install",
        "install failed",
        "installation issue",
    ],
    "REQUEST_SHIPMENT_STATUS": [
        "tracking number",
        "track my order",
        "shipment status",
        "where is my order",
        "where is my shipment",
        "when will it arrive",
        "order status",
        "where is my package",
        "has it shipped",
    ],
    "DISPUTE_SERVICE_FEE": [
        "charged a fee",
        "service fee",
        "late fee",
        "unexpected fee",
    ],
    "REPORT_DUPLICATE_CHARGE": [
        "duplicate charge",
        "charged twice",
        "double charged",
        "two charges",
        "duplicate payment",
    ],
    "REQUEST_REFUND": [
        "i want a refund",
        "refund please",
        "get my money back",
        "process a refund",
    ],
    "INQUIRE_CHARGE_REASON": [
        "why was i charged",
        "what is this charge",
        "what's this charge for",
        "what was i charged for",
        "can you explain this charge",
    ],
    "DISPUTE_UNAUTHORIZED_CHARGE": [
        "i didn't authorize",
        "i never signed up for",
        "i didn't order",
        "did not authorize",
        "never authorized",
        "i never agreed to",
    ],
    "DISPUTE_INCORRECT_AMOUNT": [
        "incorrect amount",
        "wrong amount",
        "overcharged",
        "charged the wrong amount",
        "charged incorrectly",
    ],
    "REPORT_BILLING_ISSUE": [
        "billing issue",
        "incorrect charge",
    ],
}

ISSUE_TO_SERVICE = {
    "SUBSCRIPTION_CANCELLATION": "SUBSCRIPTION",
    "PLAN_UPGRADE": "SUBSCRIPTION",
    "PLAN_DOWNGRADE": "SUBSCRIPTION",
    "AUTO_RENEWAL_ISSUE": "SUBSCRIPTION",
    "SUBSCRIPTION_RENEWAL_ISSUE": "SUBSCRIPTION",
    "PAYMENT_FAILED": "PAYMENT",
    "CREDIT_CARD_UPDATE": "PAYMENT",
    "CARD_DECLINED": "PAYMENT",
    "UNAUTHORIZED_TRANSACTION": "PAYMENT",
    "MISSING_STATEMENT": "PAYMENT",
    "PREMIUM_PAYMENT_ISSUE": "PAYMENT",
    "BILLING_DISPUTE": "PAYMENT",
    "DUPLICATE_CHARGE": "PAYMENT",
    "MISSING_REFUND": "PAYMENT",
    "REPORTING_ISSUE": "DASHBOARD",
    "DATA_EXPORT_ERROR": "EXPORTS",
    "API_ERROR": "API",
    "DELIVERY_DELAY": "DELIVERY",
    "LOST_PACKAGE": "DELIVERY",
    "DAMAGED_PACKAGE": "DELIVERY",
    "TRACKING_ISSUE": "DELIVERY",
}
ISSUE_TO_DOMAIN = {
    "BILLING_DISPUTE": "BILLING",
    "DUPLICATE_CHARGE": "BILLING",
    "PAYMENT_FAILED": "BILLING",
    "MISSING_REFUND": "BILLING",
    "INVALID_COUPON": "BILLING",
    "CREDIT_CARD_UPDATE": "BILLING",
    "AUTO_RENEWAL_ISSUE": "BILLING",
    "CARD_DECLINED": "BILLING",
    "UNAUTHORIZED_TRANSACTION": "BILLING",
    "MISSING_STATEMENT": "BILLING",
    "INVOICE_REQUEST": "BILLING",
    "REFUND_DELAY": "BILLING",
    "UNEXPECTED_CHARGE": "BILLING",
    "OVERCHARGE": "BILLING",
    "PREMIUM_PAYMENT_ISSUE": "BILLING",
    "REFUND_ISSUE": "BILLING",
    "FEE_DISPUTE": "BILLING",
    "LOGIN_FAILURE": "ACCOUNT",
    "AUTHENTICATION_ERROR": "ACCOUNT",
    "ACCOUNT_LOCKED": "ACCOUNT",
    "KYC_VERIFICATION": "ACCOUNT",
    "ACCOUNT_CREATION_ERROR": "ACCOUNT",
    "ACCOUNT_UPDATE": "ACCOUNT",
    "PROFILE_UPDATE": "ACCOUNT",
    "ACCOUNT_HACKED": "SECURITY",
    "SECURITY_ISSUE": "SECURITY",
    "INTERNET_OUTAGE": "TECHNICAL",
    "SLOW_INTERNET": "TECHNICAL",
    "SERVER_DOWN": "TECHNICAL",
    "APP_CRASH": "TECHNICAL",
    "OVERHEATING_DEVICE": "TECHNICAL",
    "CONNECTIVITY": "TECHNICAL",
    "PERFORMANCE": "TECHNICAL",
    "WIFI_ISSUE": "TECHNICAL",
    "OUTAGE": "TECHNICAL",
    "SYNC_ISSUE": "TECHNICAL",
    "DELIVERY_DELAY": "FULFILLMENT",
    "LOST_PACKAGE": "FULFILLMENT",
    "DAMAGED_PACKAGE": "FULFILLMENT",
    "WRONG_ITEM": "FULFILLMENT",
    "TRACKING_ISSUE": "FULFILLMENT",
    "CUSTOMS_HOLD": "FULFILLMENT",
    "PRODUCT_NOT_RECEIVED": "FULFILLMENT",
    "ADDRESS_CHANGE": "FULFILLMENT",
    "WAREHOUSE_DELAY": "FULFILLMENT",
    "OUT_OF_STOCK": "FULFILLMENT",
    "PREORDER_DELAY": "FULFILLMENT",
    "DELIVERY_ISSUE": "FULFILLMENT",
    "API_ERROR": "API",
    "REPORTING_ISSUE": "API",
    "DATA_EXPORT_ERROR": "API",
    "EMAIL_INTEGRATION_ISSUE": "API",
    "ACCOUNT_SYNC_ERROR": "API",
    "APPOINTMENT_RESCHEDULE": "BOOKINGS",
    "RETURN_REQUEST": "RETURNS",
    "EXCHANGE_REQUEST": "RETURNS",
    "RETURN_REFUSED": "RETURNS",
    "EXPIRED_RETURN_WINDOW": "RETURNS",
    "ORDER_CANCELLATION": "RETURNS",
    "SUBSCRIPTION_CANCELLATION": "SUBSCRIPTION",
    "SUBSCRIPTION_ISSUE": "SUBSCRIPTION",
    "PLAN_UPGRADE": "PRODUCT",
    "PLAN_DOWNGRADE": "PRODUCT",
    "PRODUCT_ISSUE": "PRODUCT",
    "DATA_PRIVACY_REQUEST": "ACCOUNT",
    "MULTIPLE_ACCOUNTS": "ACCOUNT",
}

TRIGGER_CAUSE_KEYWORDS = {
    "FIELD_LOCKED": [
        "field is locked",
        "field was locked",
        "field locked",
        "can't edit the field",
        "cannot edit the field",
        "field cannot be changed",
        "the field is locked",
    ],
    "ACCOUNT_LOCKED": [
        "account is locked",
        "account locked",
        "locked out of",
        "account has been locked",
        "account was locked",
    ],
    "MISSING_DELIVERY": [
        "missing delivery",
        "not delivered",
        "delivery missing",
        "never arrived",
        "didn't receive it",
        "hasn't arrived",
        "still hasn't arrived",
        "not received",
    ],
    "PRICE_INCREASE": [
        "price increase",
        "price went up",
        "cost more",
        "more expensive",
        "rate increase",
        "bill increased",
        "prices went up",
        "price raised",
    ],
    "BETTER_ALTERNATIVE": [
        "found a better",
        "switching to",
        "better deal",
        "cheaper alternative",
        "found a competitor",
        "better option",
    ],
    "SYSTEM_ERROR": [
        "system error",
        "got an error",
        "error message",
        "error code",
        "site error",
        "app error",
        "it showed an error",
    ],
    "PRODUCT_FAILURE": [
        "stopped working",
        "not working anymore",
        "broke down",
        "has failed",
        "malfunction",
        "stopped functioning",
    ],
    "UNAUTHORIZED_ACTIVITY": [
        "didn't authorize",
        "didn't do this",
        "wasn't me",
        "someone else did",
        "i never authorized",
    ],
    "PAYMENT_DECLINED": [
        "payment failed",
        "card declined",
        "payment rejected",
        "payment was declined",
        "card was declined",
    ],
    "SERVICE_DISRUPTION": [
        "service was down",
        "service stopped",
        "because of the outage",
        "outage caused",
        "service disruption",
    ],
    "DUPLICATE_CHARGE": [
        "charged twice",
        "charged me twice",
        "billed twice",
        "two charges",
        "double charged",
        "duplicate charge",
        "billed again",
        "charged again",
    ],
    "CONNECTIVITY_DROPS": [
        "keeps dropping",
        "connection drops",
        "keeps disconnecting",
        "intermittent connection",
        "connection keeps cutting out",
        "drops every",
        "disconnects randomly",
        "keeps going out",
    ],
    "REFUND_NOT_RECEIVED": [
        "refund hasn't",
        "haven't received my refund",
        "still waiting for my refund",
        "refund not received",
        "where is my refund",
        "my refund hasn't come",
        "never got my refund",
        "refund hasn't arrived",
    ],
    "TRACKING_NOT_ASSIGNED": [
        "no tracking number",
        "tracking not assigned",
        "tracking hasn't been assigned",
        "still no tracking",
        "replacement hasn't shipped",
        "hasn't been shipped yet",
        "no shipment update",
    ],
    "UNAUTHORIZED_LOGIN_ALERT": [
        "got an email saying someone signed",
        "unexpected login alert",
        "login alert",
        "someone signed into my account from",
        "signed in from another",
        "login from a different location",
        "unauthorized login",
        "account access alert",
    ],
    "REQUEST_CANCELLATION": [
        "want to cancel",
        "would like to cancel",
        "cancel my plan",
        "looking to cancel",
        "need to cancel",
        "i'd like to cancel",
        "thinking of cancelling",
        "cancelling my subscription",
    ],
}

CALL_TYPE_TO_DOMAIN = {
    "BILLING": "BILLING",
    "TECHNICAL": "PERFORMANCE",
    "SALES": "PRODUCT",
    "SUPPORT": "SUPPORT",
    "RETENTION": "RETENTION",
    "LOGISTICS": "LOGISTICS",
    "ACCOUNT_MANAGEMENT": "ACCOUNT_MANAGEMENT",
    "FEEDBACK": "FEEDBACK",
    "RETURNS": "RETURNS",
}

# ── Multilingual / speaker detection ──

AGENT_SPEAKER_LABELS = ["agent"]
CUSTOMER_SPEAKER_LABELS = ["customer", "caller", "client"]

# ── Timeline defaults (English) ──

TIMELINE_KEYWORDS = {
    "tomorrow": "TOMORROW",
    "today": "TODAY",
}

TIMELINE_PATTERNS = [
    (r"(\d+)\s*[–\-]\s*(\d+)\s*business\s*days?", "{0}-{1}d"),
    (r"(\d+)\s*to\s*(\d+)\s*business\s*days?", "{0}-{1}d"),
    (r"within\s+(\d+)\s*hours?", "{0}h"),
    (r"within\s+(\d+)\s*(?:business\s+)?days?", "{0}d"),
    (r"in\s+(?:a\s+)?(\d+)\s*hours?", "{0}h"),
    (r"in\s+(?:a\s+)?(\d+)\s*(?:business\s+)?days?", "{0}d"),
    (r"in\s+the\s+next\s+(\d+[-\s]?\d*)\s*(?:business\s+)?days?", "{0}d"),
]

# ── Amount reason context ──

AMOUNT_REASON_CONTEXT = [
    ("duplicate", "DUPLICATE_CHARGE"),
    ("refund", "REFUND"),
    ("extra", "EXTRA_CHARGE"),
    ("discount", "DISCOUNT"),
    ("credit", "CREDIT"),
    ("fee", "FEE"),
    ("charge", "CHARGE"),
    ("charged", "CHARGE"),
]

# ── Redacted field context ──

REDACTED_FIELD_CONTEXT = [
    ("email", "EMAIL_REDACTED"),
    ("phone", "PHONE_REDACTED"),
    ("number", "PHONE_REDACTED"),
    ("address", "ADDRESS_REDACTED"),
    ("name", "NAME_REDACTED"),
]

# ── Call type detection ──

CALL_TYPE_SALES_KEYWORDS = [
    "upgrade",
    "upgrading",
    "pricing",
    "buy",
    "interested in",
    "trial",
    "plan features",
    "plan comparison",
    "considering upgrading",
    "switch to",
    "move to a higher",
    "business pro",
]

# ── Name extraction patterns ──

NAME_INTRO_PATTERNS = [
    r"(?:my name is|i'?m|this is)\s+([A-Z][a-z]+)",
]

NAME_THANKS_PATTERNS = [
    r"thank(?:s| you),\s+([A-Z][a-z]+)",
]

NAME_CHANGE_PATTERNS = [
    r"\b(?:change|update)\s+(?:my\s+)?(?:name\s+)?(?:from\s+)?\w+\s+to\s+\w+",
]

AGENT_NAME_PATTERNS = [
    r"(?:my name is|this is)\s+([A-Z][a-z]+)",
]

# ── Delay context words ──

DELAY_CONTEXT_WORDS = ["waiting", "been", "ago", "since"]

# ── Extra commitment patterns ──

EXTRA_COMMITMENT_PATTERNS = {
    "PAUSE_EXPIRY_REMINDER": [
        "reminder before it resumes",
        "reminder before your subscription resumes",
        "remind you before it resumes",
        "notify you before it resumes",
        "get a reminder before",
        "reminder when it's about to resume",
        "reminder before the pause ends",
        "notified before it resumes",
        "get a reminder",
    ],
    "CONFIRMATION_EMAIL": [
        "send you a confirmation",
        "confirmation email",
        "you'll receive an email",
        "email confirmation",
        "include the refund reference",
        "include the reference number",
        "i'll include",
        "email with the reference",
        "email you the reference",
        "send a confirmation",
        "email once",
        "email update",
    ],
    "FOLLOWUP": [
        "i'll follow up",
        "follow up with you",
        "personally follow up",
        "follow up tomorrow",
        "mark your account for follow-up",
        "i'll mark your account",
        "you'll receive a message",
        "receive a message once",
        "message once the",
        "once it's fully restored",
        "once service is restored",
        "once the network team",
        "i'll call you back",
        "schedule a callback",
        "callback for you",
    ],
    "MONITORING": [
        "monitor",
        "keep an eye on",
        "watching",
        "personally keep an eye",
    ],
    "BILLING_EXTENSION": [
        "extend your current billing cycle",
        "extend your billing cycle",
        "billing cycle extension",
        "extend billing cycle",
        "billing extension",
        "extend your billing",
    ],
    "CREDIT_PROMISE": [
        "credit applied",
        "you'll see a credit",
        "credit within",
        "credit will be applied",
        "a credit of",
        "credit you",
        "reversed the charge",
    ],
    "REFUND_PROMISE": [
        "file the refund",
        "submit the refund",
        "once i file the refund",
        "once the refund",
        "refund request",
        "refund will reflect",
    ],
}

# ── Promise timeline patterns ──

PROMISE_TIMELINE_PATTERNS = [
    (r"within\s+(\d+)\s*hours?", "{0}h"),
    (r"within\s+(\d+)\s*days?", "{0}d"),
    (r"by\s+(monday|tuesday|wednesday|thursday|friday|saturday|sunday)", "{0}"),
    (r"next\s+(week|month)", "NEXT_{0}"),
    (r"in\s+the\s+next\s+(\d+[-\s]?\d*)\s*(?:business\s+)?days?", "{0}d"),
]

# ── Disputed amount keywords ──

DISPUTED_AMOUNT_KEYWORDS = ["charge", "bill", "statement", "payment"]

# ── Promise confidence strong indicators ──

PROMISE_CONFIDENCE_STRONG = ["will", "going to", "i'll", "we'll", "definitely"]

# ── Promise commitment token overrides ──
# Replaces vocabulary defaults for EN.  Key changes vs vocabulary:
#   - DELIVERY_PROMISE: "send you" removed (too generic, causes false positives)
#   - REFUND_PROMISE: added "file the refund", "once i file"
#   - CREDIT_PROMISE: added "credit applied", "reversed the charge"
#   - FOLLOW_UP_EMAIL: added "confirmation email", "email update"

PROMISE_COMMITMENT_TOKENS = {
    "CALLBACK": [
        "i'll call you back",
        "we'll call you",
        "expect a call",
        "call you within",
        "reach out to you",
        "follow up with a call",
        "give you a call",
        "call you tomorrow",
    ],
    "FOLLOW_UP_EMAIL": [
        "send you an email",
        "email you",
        "email confirmation",
        "you'll receive an email",
        "sending an email",
        "email with details",
        "confirmation email",
        "send a confirmation email",
        "email update",
        "email once",
        "you'll get a confirmation email",
    ],
    "TECHNICIAN_VISIT": [
        "technician will",
        "send a technician",
        "tech will come",
        "schedule a visit",
        "someone will come out",
        "on-site visit",
        "technician visit",
        "dispatch a technician",
    ],
    "CREDIT_PROMISE": [
        "credit your account",
        "apply a credit",
        "give you a credit",
        "credit of",
        "account credit",
        "credit will be applied",
        "credit applied",
        "reversed the charge",
        "credit you",
        "you'll see a credit",
        "credit within",
    ],
    "REFUND_PROMISE": [
        "refund will",
        "you'll receive a refund",
        "process the refund",
        "refund of",
        "money back",
        "issue a refund",
        "refund will be processed",
        "file the refund",
        "once i file the refund",
        "submit the refund",
        "refund request",
    ],
    "DELIVERY_PROMISE": [
        "will be delivered",
        "arrive by",
        "ship it",
        "expect delivery",
        "shipped by",
        "deliver within",
        "will be shipped",
        "send you a replacement",
        "send you a new",
        "send you the",
    ],
    "RESOLUTION_PROMISE": [
        "will be resolved",
        "should be fixed",
        "take care of this",
        "handle this",
        "sort this out",
        "fix this for you",
    ],
}
