import type {
  JobTaxonomyKeywordCategory,
  JobTaxonomyKeywordEntry,
  JobTaxonomySettings,
  StudioClassificationRule,
} from "../types/jobs-taxonomy";

const sortCounters = new Map<string, number>();

const nextSortOrder = (key: string): number => {
  const current = sortCounters.get(key) ?? 0;
  sortCounters.set(key, current + 1);
  return current;
};

const createKeywordEntry = (
  category: JobTaxonomyKeywordCategory,
  label: string,
  synonyms: readonly string[] = [],
): JobTaxonomyKeywordEntry => {
  const sortOrder = nextSortOrder(category);
  return {
    id: `${category}:${String(sortOrder)}:${label
      .toLowerCase()
      .replaceAll(/\s+/g, "-")
      .replaceAll(/[^a-z0-9#+:/-]/g, "")}`,
    category,
    label,
    synonyms: [...synonyms],
    sortOrder,
    enabled: true,
  };
};

const createStudioRule = (
  studioType: StudioClassificationRule["studioType"],
  keyword: string,
): StudioClassificationRule => {
  const sortOrder = nextSortOrder(`studio:${studioType}`);
  return {
    id: `${studioType}:${String(sortOrder)}:${keyword
      .toLowerCase()
      .replaceAll(/\s+/g, "-")
      .replaceAll(/[^a-z0-9/-]/g, "")}`,
    studioType,
    keyword,
    sortOrder,
    enabled: true,
  };
};

export const DEFAULT_JOB_TAXONOMY_KEYWORDS: readonly JobTaxonomyKeywordEntry[] = [
  createKeywordEntry("remote-location", "remote"),
  createKeywordEntry("remote-location", "work from home"),
  createKeywordEntry("remote-location", "wfh"),
  createKeywordEntry("remote-location", "anywhere"),
  createKeywordEntry("hybrid-location", "hybrid"),
  createKeywordEntry("requirement", "C++"),
  createKeywordEntry("requirement", "C#"),
  createKeywordEntry("requirement", "Unity"),
  createKeywordEntry("requirement", "Unreal Engine"),
  createKeywordEntry("requirement", "Python"),
  createKeywordEntry("requirement", "Java"),
  createKeywordEntry("requirement", "JavaScript"),
  createKeywordEntry("requirement", "Graphics Programming"),
  createKeywordEntry("requirement", "Game Design"),
  createKeywordEntry("requirement", "Level Design"),
  createKeywordEntry("requirement", "3D Modeling"),
  createKeywordEntry("requirement", "Animation"),
  createKeywordEntry("requirement", "UI/UX"),
  createKeywordEntry("requirement", "Networking"),
  createKeywordEntry("requirement", "Multiplayer"),
  createKeywordEntry("requirement", "AI Programming"),
  createKeywordEntry("technology", "Unity"),
  createKeywordEntry("technology", "Unreal Engine"),
  createKeywordEntry("technology", "Godot"),
  createKeywordEntry("technology", "CryEngine"),
  createKeywordEntry("technology", "Blender"),
  createKeywordEntry("technology", "Maya"),
  createKeywordEntry("technology", "3ds Max"),
  createKeywordEntry("technology", "Substance Painter"),
  createKeywordEntry("technology", "ZBrush"),
  createKeywordEntry("technology", "Photoshop"),
  createKeywordEntry("technology", "Git"),
  createKeywordEntry("technology", "Perforce"),
  createKeywordEntry("technology", "Jira"),
  createKeywordEntry("technology", "C++"),
  createKeywordEntry("technology", "C#"),
  createKeywordEntry("technology", "Python"),
  createKeywordEntry("technology", "Lua"),
  createKeywordEntry("technology", "DirectX"),
  createKeywordEntry("technology", "OpenGL"),
  createKeywordEntry("technology", "Vulkan"),
  createKeywordEntry("technology", "Metal"),
  createKeywordEntry("technology", "AWS"),
  createKeywordEntry("technology", "Azure"),
  createKeywordEntry("technology", "Docker"),
  createKeywordEntry("technology", "Kubernetes"),
  createKeywordEntry("genre", "RPG"),
  createKeywordEntry("genre", "FPS"),
  createKeywordEntry("genre", "MMORPG"),
  createKeywordEntry("genre", "MOBA"),
  createKeywordEntry("genre", "Battle Royale"),
  createKeywordEntry("genre", "Strategy"),
  createKeywordEntry("genre", "Simulation"),
  createKeywordEntry("genre", "Sports"),
  createKeywordEntry("genre", "Racing"),
  createKeywordEntry("genre", "Horror"),
  createKeywordEntry("genre", "Platformer"),
  createKeywordEntry("genre", "Puzzle"),
  createKeywordEntry("platform", "PC"),
  createKeywordEntry("platform", "Console"),
  createKeywordEntry("platform", "Mobile"),
  createKeywordEntry("platform", "PlayStation"),
  createKeywordEntry("platform", "Xbox"),
  createKeywordEntry("platform", "Switch"),
  createKeywordEntry("platform", "Steam"),
  createKeywordEntry("platform", "VR"),
  createKeywordEntry("platform", "AR"),
  createKeywordEntry("platform", "Web"),
  createKeywordEntry("role", "Game Designer"),
  createKeywordEntry("role", "Level Designer"),
  createKeywordEntry("role", "Systems Designer"),
  createKeywordEntry("role", "Narrative Designer"),
  createKeywordEntry("role", "Quest Designer"),
  createKeywordEntry("role", "Combat Designer"),
  createKeywordEntry("role", "Economy Designer"),
  createKeywordEntry("role", "UI/UX Designer"),
  createKeywordEntry("role", "Gameplay Programmer"),
  createKeywordEntry("role", "Engine Programmer"),
  createKeywordEntry("role", "Graphics Programmer"),
  createKeywordEntry("role", "AI Programmer"),
  createKeywordEntry("role", "Network Programmer"),
  createKeywordEntry("role", "Tools Programmer"),
  createKeywordEntry("role", "Build Engineer"),
  createKeywordEntry("role", "Technical Artist"),
  createKeywordEntry("role", "Concept Artist"),
  createKeywordEntry("role", "3D Modeler"),
  createKeywordEntry("role", "Animator"),
  createKeywordEntry("role", "VFX Artist"),
  createKeywordEntry("role", "Environment Artist"),
  createKeywordEntry("role", "Character Artist"),
  createKeywordEntry("role", "Texture Artist"),
  createKeywordEntry("role", "Sound Designer"),
  createKeywordEntry("role", "Music Composer"),
  createKeywordEntry("role", "Audio Engineer"),
  createKeywordEntry("role", "Producer"),
  createKeywordEntry("role", "Associate Producer"),
  createKeywordEntry("role", "Executive Producer"),
  createKeywordEntry("role", "QA Tester"),
  createKeywordEntry("role", "QA Lead"),
  createKeywordEntry("role", "QA Automation Engineer"),
  createKeywordEntry("role", "Community Manager"),
  createKeywordEntry("role", "DevOps Engineer"),
  createKeywordEntry("role", "Data Analyst"),
  createKeywordEntry("role", "Live Ops Manager"),
  createKeywordEntry("role", "Monetization Designer"),
  createKeywordEntry("role", "Localization Specialist"),
  createKeywordEntry("role", "Art Director"),
  createKeywordEntry("role", "Creative Director"),
  createKeywordEntry("role", "Technical Director"),
  createKeywordEntry("role", "Game Director"),
  createKeywordEntry("role", "Studio Head"),
  createKeywordEntry("role", "Project Manager"),
] as const;

export const DEFAULT_STUDIO_CLASSIFICATION_RULES: readonly StudioClassificationRule[] = [
  createStudioRule("AAA", "riot"),
  createStudioRule("AAA", "epic"),
  createStudioRule("AAA", "blizzard"),
  createStudioRule("AAA", "electronic arts"),
  createStudioRule("AAA", "ea"),
  createStudioRule("AAA", "activision"),
  createStudioRule("AAA", "ubisoft"),
  createStudioRule("AAA", "rockstar"),
  createStudioRule("AAA", "bungie"),
  createStudioRule("AAA", "naughty dog"),
  createStudioRule("AAA", "insomniac"),
  createStudioRule("AAA", "respawn"),
  createStudioRule("AAA", "guerrilla"),
  createStudioRule("AAA", "treyarch"),
  createStudioRule("AAA", "sledgehammer"),
  createStudioRule("AAA", "infinity ward"),
  createStudioRule("AAA", "2k"),
  createStudioRule("AAA", "square enix"),
  createStudioRule("AAA", "obsidian"),
  createStudioRule("AAA", "gearbox"),
  createStudioRule("AAA", "playground games"),
  createStudioRule("AAA", "sucker punch"),
  createStudioRule("AAA", "arkane"),
  createStudioRule("AAA", "machinegames"),
  createStudioRule("AAA", "machine games"),
  createStudioRule("AAA", "cd projekt"),
  createStudioRule("AAA", "wargaming"),
  createStudioRule("AAA", "mojang"),
  createStudioRule("AAA", "firaxis"),
  createStudioRule("AAA", "avalanche"),
  createStudioRule("AAA", "amplitude"),
  createStudioRule("AAA", "cloud imperium"),
  createStudioRule("AAA", "cloud chamber"),
  createStudioRule("AAA", "netflix games"),
  createStudioRule("AAA", "lightspeed"),
  createStudioRule("AAA", "striking distance"),
  createStudioRule("AAA", "bandai namco"),
  createStudioRule("AAA", "capcom"),
  createStudioRule("AAA", "sega"),
  createStudioRule("AAA", "konami"),
  createStudioRule("AAA", "take-two"),
  createStudioRule("AAA", "take two"),
  createStudioRule("AAA", "bethesda"),
  createStudioRule("AAA", "larian"),
  createStudioRule("AAA", "double fine"),
  createStudioRule("AAA", "second dinner"),
  createStudioRule("AAA", "archetype entertainment"),
  createStudioRule("Mobile", "supercell"),
  createStudioRule("Mobile", "zynga"),
  createStudioRule("Mobile", "king"),
  createStudioRule("Mobile", "jam city"),
  createStudioRule("Mobile", "wildlife"),
  createStudioRule("Mobile", "playq"),
  createStudioRule("Mobile", "voodoo"),
  createStudioRule("Mobile", "niantic"),
  createStudioRule("Mobile", "pokemon"),
  createStudioRule("Mobile", "demiurge"),
  createStudioRule("VR/AR", "meta"),
  createStudioRule("VR/AR", "oculus"),
  createStudioRule("Platform", "valve"),
  createStudioRule("Platform", "unity"),
  createStudioRule("Platform", "unreal"),
  createStudioRule("Platform", "nvidia"),
  createStudioRule("Platform", "roblox"),
  createStudioRule("Platform", "discord"),
  createStudioRule("Esports", "esl"),
  createStudioRule("Esports", "faceit"),
  createStudioRule("Esports", "hitmarker"),
] as const;

export const DEFAULT_JOB_TAXONOMY_SETTINGS: JobTaxonomySettings = {
  keywords: [...DEFAULT_JOB_TAXONOMY_KEYWORDS],
  studioRules: [...DEFAULT_STUDIO_CLASSIFICATION_RULES],
};
