import { DEFAULT_CURRENCY_CODE, DEFAULT_CURRENCY_SYMBOL } from '@/constants/platformDefaults';

export const moduleRegistry = {
  crm: {
    title: 'CRM Workspace',
    description: 'Customers, people, companies, leads, deals, activities, communication history, and enterprise offer flows.',
    themeColor: '#4f46e5', // Solid indigo
    stats: [
      ['Total Entities', 9],
      ['Automation Status', 'Active'],
      ['Active Channels', 3],
    ],
    workflows: [
      { name: 'Capture inbound lead & qualify', link: '/lead' },
      { name: 'Manage active deal pipeline stages', link: '/deals' },
      { name: 'Generate and send commercial proposals', link: '/offers' },
    ],
    entities: [
      {
        entity: 'client',
        label: 'Customers',
        icon: 'UserOutlined',
        description: 'Primary customer profiles representing accounts and contract entities.',
      },
      {
        entity: 'contact',
        label: 'People',
        icon: 'ContactsOutlined',
        description: 'Individual contact profiles linked to customer companies and vendors.',
      },
      {
        entity: 'company',
        label: 'Companies',
        icon: 'ApartmentOutlined',
        description: 'Business accounts, organizations, and corporate partners.',
      },
      {
        entity: 'lead',
        label: 'Leads',
        icon: 'UserAddOutlined',
        description: 'Prospects and marketing inquiries currently undergoing qualification.',
      },
      {
        entity: 'deal',
        label: 'Deals',
        icon: 'DollarOutlined',
        description: 'Sales opportunities moving through stage progression pipeline.',
      },
      {
        entity: 'offer',
        label: 'Offers',
        icon: 'GiftOutlined',
        description: 'Proposals and pricing agreements drafted for prospects.',
      },
      {
        entity: 'pipelinestage',
        label: 'Pipeline Stages',
        icon: 'OrderedListOutlined',
        description: 'Custom deal pipeline column configurations and probabilities.',
      },
      {
        entity: 'activity',
        label: 'Activities',
        icon: 'NotificationOutlined',
        description: 'Notes, calls, and actions logged by workspace operators.',
      },
      {
        entity: 'communicationlog',
        label: 'Communication Logs',
        icon: 'MessageOutlined',
        description: 'Historical records of outbound and inbound contact touches.',
      },
    ],
  },
  sales: {
    title: 'Sales Workspace',
    description: 'Quotes, invoices, payments, offers, sales orders, approvals, and finance-linked commercial operations.',
    themeColor: '#10b981', // Solid emerald green
    stats: [
      ['Sales Entities', 7],
      ['Pending Approvals', '2 Required'],
      ['Forecast Status', 'Ready'],
    ],
    workflows: [
      { name: 'Convert approved quote to invoice', link: '/quote' },
      { name: 'Review and approve discount exceptions', link: '/records/approvalrequest' },
      { name: 'Issue payment requests and reminders', link: '/invoice' },
    ],
    entities: [
      {
        entity: 'offer',
        label: 'Offers / Proforma',
        icon: 'GiftOutlined',
        description: 'Commercial proforma quotes and proposals waiting conversion.',
      },
      {
        entity: 'quote',
        label: 'Quotes',
        icon: 'FileTextOutlined',
        description: 'Formal price quotes generated for customer sign-off.',
      },
      {
        entity: 'invoice',
        label: 'Invoices',
        icon: 'FileDoneOutlined',
        description: 'Billed invoices tracking outstanding accounts receivable.',
      },
      {
        entity: 'payment',
        label: 'Payments',
        icon: 'WalletOutlined',
        description: 'Customer transactions logged and matched to open invoices.',
      },
      {
        entity: 'salesorder',
        label: 'Sales Orders',
        icon: 'ShoppingCartOutlined',
        description: 'Customer purchase confirmations awaiting fulfillment and delivery.',
      },
      {
        entity: 'salestarget',
        label: 'Sales Targets',
        icon: 'AimOutlined',
        description: 'Quota and performance benchmarks set for individual sales teams.',
      },
      {
        entity: 'approvalrequest',
        label: 'Approval Requests',
        icon: 'CheckSquareOutlined',
        description: 'Discount, credit, or policy exceptions requiring management approval.',
      },
    ],
  },
  inventory: {
    title: 'Catalog and Inventory',
    description: 'Products, categories, orders, purchases, suppliers, and fulfillment-facing inventory records.',
    themeColor: '#f59e0b', // Solid amber orange
    stats: [
      ['SKU Count', 6],
      ['Stock Tracking', 'Active'],
      ['Procurement Link', 'Synced'],
    ],
    workflows: [
      { name: 'Add new product specifications', link: '/products' },
      { name: 'Reorder items and generate purchase orders', link: '/purchases' },
      { name: 'Update vendor catalogs & onboarding status', link: '/suppliers' },
    ],
    entities: [
      {
        entity: 'product',
        label: 'Products',
        icon: 'BoxPlotOutlined',
        description: 'Catalog products, service packages, and stock items.',
      },
      {
        entity: 'productcategory',
        label: 'Product Categories',
        icon: 'AppstoreOutlined',
        description: 'Product taxonomies, tags, and classification groups.',
      },
      {
        entity: 'order',
        label: 'Orders',
        icon: 'ShoppingOutlined',
        description: 'Customer sales orders driving inventory depletion.',
      },
      {
        entity: 'purchaseorder',
        label: 'Purchases',
        icon: 'AuditOutlined',
        description: 'Supplier purchases tracking incoming items and costs.',
      },
      {
        entity: 'supplier',
        label: 'Suppliers',
        icon: 'TeamOutlined',
        description: 'Product suppliers, inventory partners, and manufacturers.',
      },
      {
        entity: 'vendor',
        label: 'Vendors',
        icon: 'ShopOutlined',
        description: 'Outsourced vendors and local service contractors.',
      },
    ],
  },
  marketing: {
    title: 'Marketing Automation',
    description: 'Campaigns, audience segments, social posting, public forms, AI content, and lead-score feedback loops.',
    themeColor: '#e1306c', // Solid pinkish red
    stats: [
      ['Campaigns', 7],
      ['AI Engine', 'Enabled'],
      ['Channels Support', 5],
    ],
    workflows: [
      { name: 'Draft marketing content with AI', link: '/marketing' },
      { name: 'Create custom lead capture forms', link: '/forms' },
      { name: 'Publish & schedule social media campaigns', link: '/ai-studio/social' },
    ],
    entities: [
      {
        entity: 'campaign',
        label: 'Campaigns',
        icon: 'RocketOutlined',
        description: 'Email, Whatsapp, or multichannel marketing campaigns.',
      },
      {
        entity: 'audiencesegment',
        label: 'Audience Segments',
        icon: 'TeamOutlined',
        description: 'Filtered customer segments based on actions or attributes.',
      },
      {
        entity: 'landingform',
        label: 'Landing Forms',
        icon: 'FormOutlined',
        description: 'Capture parameters and styles for integrated landing sites.',
      },
      {
        entity: 'publicform',
        label: 'Public Forms',
        icon: 'GlobalOutlined',
        description: 'Embeddable data capture forms saving contacts directly to CRM.',
      },
      {
        entity: 'campaignevent',
        label: 'Campaign Events',
        icon: 'NotificationOutlined',
        description: 'Interactions logged from campaigns (clicks, opens, unsubscribes).',
      },
      {
        entity: 'socialpost',
        label: 'Social Posts',
        icon: 'ShareAltOutlined',
        description: 'Scheduled posts for Facebook, Instagram, or LinkedIn.',
      },
      {
        entity: 'contentasset',
        label: 'Content Assets',
        icon: 'FileTextOutlined',
        description: 'AI drafts, copywriting concepts, and media assets.',
      },
    ],
  },
  finance: {
    title: 'Finance Management',
    description: 'Accounts, invoices, payments, expenses, taxes, payment modes, currencies, and document output settings.',
    themeColor: '#8b5cf6', // Solid violet purple
    stats: [
      ['Accounts Count', 11],
      ['Currencies', 'Multi-currency'],
      ['Compliance Logs', 'Enabled'],
    ],
    workflows: [
      { name: 'Reconcile outstanding payments', link: '/dashboard' },
      { name: 'Log operating expense records', link: '/dashboard' },
      { name: 'Configure regional tax profiles', link: '/taxes' },
    ],
    entities: [
      {
        entity: 'account',
        label: 'Accounts',
        icon: 'BankOutlined',
        description: 'General ledger charts, bank accounts, and asset codes.',
      },
      {
        entity: 'ledgerentry',
        label: 'Ledger Entries',
        icon: 'OrderedListOutlined',
        description: 'Double-entry bookkeeping transactions recorded.',
      },
      {
        entity: 'invoice',
        label: 'Invoices',
        icon: 'FileDoneOutlined',
        description: 'Customer invoices representing revenue generated.',
      },
      {
        entity: 'payment',
        label: 'Payments',
        icon: 'WalletOutlined',
        description: 'Customer payments mapped to invoices or ledger items.',
      },
      {
        entity: 'expense',
        label: 'Expenses',
        icon: 'CalculatorOutlined',
        description: 'Operating expenses, purchases, and utilities bills.',
      },
      {
        entity: 'expensecategory',
        label: 'Expense Categories',
        icon: 'FolderOpenOutlined',
        description: 'Operating expense taxonomy codes.',
      },
      {
        entity: 'bill',
        label: 'Bills',
        icon: 'AuditOutlined',
        description: 'Supplier invoices received tracking outgoing payments.',
      },
      {
        entity: 'budget',
        label: 'Budgets',
        icon: 'DashboardOutlined',
        description: 'Departmental budgets tracking allocated vs actual costs.',
      },
      {
        entity: 'currency',
        label: 'Currencies',
        icon: 'GlobalOutlined',
        description: 'Active operating and reporting currencies.',
      },
      {
        entity: 'paymentmode',
        label: 'Payment Modes',
        icon: 'CreditCardOutlined',
        description: 'Customer-facing receipt channels (Bank, Stripe, Cash).',
      },
      {
        entity: 'taxes',
        label: 'Taxes',
        icon: 'PercentageOutlined',
        description: 'Country-specific sales, VAT, or withholding taxes.',
      },
      {
        entity: 'pdfsetting',
        label: 'PDF Settings',
        icon: 'SettingOutlined',
        description: 'Layout settings, logos, and signatures for invoices and quotes.',
      },
    ],
  },
  operations: {
    title: 'Operations Workspace',
    description: 'Branches, company workspaces, booking, appointments, documents, and contracts across the tenant.',
    themeColor: '#06b6d4', // Solid cyan teal
    stats: [
      ['Operational Nodes', 6],
      ['Scheduling Mode', 'Active'],
      ['Document Controls', 'Secure'],
    ],
    workflows: [
      { name: 'Schedule customer appointments & meetings', link: '/appointment' },
      { name: 'Configure operational branches & locations', link: '/branches' },
      { name: 'Review and signs business contracts', link: '/contracts' },
    ],
    entities: [
      {
        entity: 'branch',
        label: 'Branches',
        icon: 'EnvironmentOutlined',
        description: 'Corporate branches, warehouses, or local offices.',
      },
      {
        entity: 'companyworkspace',
        label: 'Company Workspaces',
        icon: 'AppstoreOutlined',
        description: 'Internal workspaces grouping branches and settings.',
      },
      {
        entity: 'calendarbooking',
        label: 'Bookings',
        icon: 'CalendarOutlined',
        description: 'Meeting or resource bookings scheduled by stakeholders.',
      },
      {
        entity: 'appointment',
        label: 'Appointments',
        icon: 'ScheduleOutlined',
        description: 'Customer-facing calendar calls and events.',
      },
      {
        entity: 'document',
        label: 'Documents',
        icon: 'FileProtectOutlined',
        description: 'Company documentation, requirements sheets, or compliance records.',
      },
      {
        entity: 'contract',
        label: 'Contracts',
        icon: 'SafetyCertificateOutlined',
        description: 'Service level, employment, or corporate business contracts.',
      },
    ],
  },
  vendors: {
    title: 'Vendor Management',
    description: 'Onboarding, contracts, purchase orders, approval chains, terms, and performance scorecards.',
    themeColor: '#ec4899', // Solid pink
    stats: [
      ['Vendors Tracked', 4],
      ['Approvals Queue', 'Active'],
      ['Quality Checks', 'Enabled'],
    ],
    workflows: [
      { name: 'Setup vendor profile & catalog', link: '/vendors' },
      { name: 'Generate procurement purchase orders', link: '/vendors' },
      { name: 'Complete vendor performance evaluations', link: '/vendors' },
    ],
    entities: [
      {
        entity: 'vendor',
        label: 'Vendors',
        icon: 'ShopOutlined',
        description: 'Outsourced vendors, suppliers, and service providers.',
      },
      {
        entity: 'vendorcontract',
        label: 'Vendor Contracts',
        icon: 'SafetyCertificateOutlined',
        description: 'Commercial vendor agreements, terms, and pricing.',
      },
      {
        entity: 'purchaseorder',
        label: 'Purchase Orders',
        icon: 'AuditOutlined',
        description: 'Supplier orders tracking procurement requirements.',
      },
      {
        entity: 'vendorscorecard',
        label: 'Vendor Scorecards',
        icon: 'AimOutlined',
        description: 'Vendor performance reports tracking quality and timing.',
      },
    ],
  },
  platform: {
    title: 'Platform Console',
    description: 'Reports, forms, API keys, automation, access control, integrations, and AI-assisted operations.',
    themeColor: '#64748b', // Solid slate gray
    stats: [
      ['System Elements', 8],
      ['Engine Status', 'Online'],
      ['API Interface', 'Active'],
    ],
    workflows: [
      { name: 'Manage event-based automation rules', link: '/automations' },
      { name: 'Generate developer API credentials', link: '/developer/api-keys' },
      { name: 'Monitor active integration accounts', link: '/ai-studio/providers' },
    ],
    entities: [
      {
        entity: 'apikey',
        label: 'Developer API Keys',
        icon: 'KeyOutlined',
        description: 'Developer credentials managing custom integrations.',
      },
      {
        entity: 'automationrule',
        label: 'Automation Rules',
        icon: 'ThunderboltOutlined',
        description: 'Rules governing automated actions based on business events.',
      },
      {
        entity: 'automationevent',
        label: 'Automation Events',
        icon: 'NotificationOutlined',
        description: 'Events generated across business modules.',
      },
      {
        entity: 'automationrun',
        label: 'Automation Runs',
        icon: 'HistoryOutlined',
        description: 'Chronological logs of automation rule execution.',
      },
      {
        entity: 'job',
        label: 'Jobs',
        icon: 'OrderedListOutlined',
        description: 'Async queues tracking pending automation jobs.',
      },
      {
        entity: 'integrationaccount',
        label: 'Integration Accounts',
        icon: 'ApiOutlined',
        description: 'Third-party accounts (Meta, Resend, OpenAI) connected.',
      },
      {
        entity: 'role',
        label: 'Roles',
        icon: 'LockOutlined',
        description: 'Access roles assigning entity-specific permissions.',
      },
      {
        entity: 'permission',
        label: 'Permissions',
        icon: 'SafetyOutlined',
        description: 'Access permissions map linked to roles and actions.',
      },
    ],
  },
};

export const allEntityConfigs = Object.values(moduleRegistry)
  .flatMap((module) => module.entities)
  .reduce((acc, config) => {
    acc[config.entity] = config;
    return acc;
  }, {});
