/**
 * Skill category definitions and mapping.
 * Skills are assigned to categories by name, with keyword fallback.
 */

export const SKILL_CATEGORIES: Record<string, string[]> = {
  'Frontend & UI': [
    'ai-sdk',
    'algorithmic-art',
    'antfu',
    'canvas-design',
    'frontend-design',
    'next-best-practices',
    'nuxt',
    'pinia',
    'shadcn-ui',
    'slidev',
    'tailwind-design-system',
    'theme-factory',
    'ui-animation',
    'unocss',
    'vercel-composition-patterns',
    'vercel-react-best-practices',
    'vercel-react-native-skills',
    'vue',
    'vue-best-practices',
    'vue-router-best-practices',
    'vueuse-functions',
    'web-artifacts-builder',
    'web-design-guidelines',
    'vite',
    'vitepress',
  ],
  'Backend & Infrastructure': [
    'architecture-patterns',
    'fastapi',
    'mcp-builder',
    'nestjs-best-practices',
    'python-performance-optimization',
    'tsdown',
    'turborepo',
    'pnpm',
    'dispatching-parallel-agents',
    'subagent-driven-development',
    'create-agent',
    'proactive-agent',
    'using-superpowers',
    'kickstart',
    'executing-plans',
    'mosaic-forge',
    'mosaic-macp',
    'mosaic-setup-cicd',
    'mosaic-jarvis',
    'mosaic-standards',
  ],
  'Testing & Quality': [
    'code-review-excellence',
    'lint',
    'pr-reviewer',
    'receiving-code-review',
    'requesting-code-review',
    'systematic-debugging',
    'test-driven-development',
    'verification-before-completion',
    'vitest',
    'vue-testing-best-practices',
    'webapp-testing',
  ],
  'Marketing & Growth': [
    'ab-test-setup',
    'analytics-tracking',
    'competitor-alternatives',
    'copy-editing',
    'copywriting',
    'email-sequence',
    'form-cro',
    'free-tool-strategy',
    'launch-strategy',
    'marketing-ideas',
    'marketing-psychology',
    'onboarding-cro',
    'page-cro',
    'paid-ads',
    'paywall-upgrade-cro',
    'popup-cro',
    'pricing-strategy',
    'product-marketing-context',
    'programmatic-seo',
    'referral-program',
    'schema-markup',
    'seo-audit',
    'signup-flow-cro',
    'social-content',
  ],
  'Product & Strategy': [
    'brainstorming',
    'brand-guidelines',
    'content-strategy',
    'writing-plans',
    'skill-creator',
    'writing-skills',
    'prd',
    'mosaic-prd',
    'mosaic-prdy',
    'mosaic-board',
  ],
  'Developer Practices': ['finishing-a-development-branch', 'using-git-worktrees'],
  'Auth & Security': [
    'better-auth-best-practices',
    'create-auth-skill',
    'email-and-password-best-practices',
    'organization-best-practices',
    'two-factor-authentication-best-practices',
  ],
  'Content & Documentation': [
    'doc-coauthoring',
    'docx',
    'internal-comms',
    'pdf',
    'pptx',
    'slack-gif-creator',
    'xlsx',
  ],
};

// Reverse lookup: skill name -> category
const SKILL_TO_CATEGORY = new Map<string, string>();
for (const [category, skills] of Object.entries(SKILL_CATEGORIES)) {
  for (const skill of skills) {
    SKILL_TO_CATEGORY.set(skill, category);
  }
}

export function categorizeSkill(name: string, description: string): string {
  const mapped = SKILL_TO_CATEGORY.get(name);
  if (mapped) return mapped;
  return inferCategoryFromDescription(description);
}

function inferCategoryFromDescription(desc: string): string {
  const lower = desc.toLowerCase();
  if (/\b(react|vue|css|frontend|ui|component|tailwind|design)\b/.test(lower))
    return 'Frontend & UI';
  if (/\b(api|backend|server|docker|infra|deploy)\b/.test(lower)) return 'Backend & Infrastructure';
  if (/\b(test|lint|review|debug|quality)\b/.test(lower)) return 'Testing & Quality';
  if (/\b(marketing|seo|copy|ads|cro|conversion|email)\b/.test(lower)) return 'Marketing & Growth';
  if (/\b(auth|security|2fa|password|credential)\b/.test(lower)) return 'Auth & Security';
  if (/\b(doc|pdf|word|sheet|writing|comms)\b/.test(lower)) return 'Content & Documentation';
  if (/\b(product|strategy|brainstorm|plan|prd)\b/.test(lower)) return 'Product & Strategy';
  return 'Developer Practices';
}
