// Готовые шаблоны правил роутинга. domains/suffixes/cidr/ports собраны из публичных
// reference-конфигов sing-box. Это пресеты «на старт», а не исчерпывающие списки.

let counter = 0;
function id(prefix) {
  counter += 1;
  return `${prefix}-${Date.now()}-${counter}`;
}

function template(name, outbound, fields) {
  return {
    id: id("tpl"),
    name,
    enabled: true,
    outbound,
    domains: [],
    domainSuffixes: [],
    domainKeywords: [],
    ipCidrs: [],
    ports: [],
    networks: [],
    ...fields,
  };
}

export const ruleTemplates = [
  {
    key: "lol-direct",
    label: "League of Legends → direct",
    description: "Riot/LoL домены и порты — играть напрямую без VPN.",
    build: () =>
      template("League of Legends", "direct", {
        domainSuffixes: [
          "leagueoflegends.com",
          "riotgames.com",
          "riotcdn.net",
          "dyn.riotcdn.net",
        ],
        ports: ["5000", "5223", "5222", "8088"],
      }),
  },
  {
    key: "discord-direct",
    label: "Discord/Vesktop → direct",
    description: "Discord voice/video и WebSocket напрямую.",
    build: () =>
      template("Discord", "direct", {
        domainSuffixes: [
          "discord.com",
          "discord.gg",
          "discord.media",
          "discordapp.com",
          "discordapp.net",
        ],
        ports: ["50000-65535"],
        networks: ["udp"],
      }),
  },
  {
    key: "telegram-vpn",
    label: "Telegram → VPN",
    description: "Telegram через выбранный VPN outbound.",
    build: () =>
      template("Telegram", "vpn", {
        domainSuffixes: [
          "telegram.org",
          "t.me",
          "telegram.me",
          "telegra.ph",
          "tdesktop.com",
        ],
        ipCidrs: [
          "149.154.160.0/20",
          "91.108.4.0/22",
          "91.108.8.0/22",
          "91.108.12.0/22",
          "91.108.16.0/22",
          "91.108.56.0/22",
        ],
      }),
  },
  {
    key: "youtube-vpn",
    label: "YouTube → VPN",
    description: "YouTube/Google Video через VPN.",
    build: () =>
      template("YouTube", "vpn", {
        domainSuffixes: [
          "youtube.com",
          "youtu.be",
          "ytimg.com",
          "googlevideo.com",
          "youtube-nocookie.com",
        ],
      }),
  },
  {
    key: "steam-direct",
    label: "Steam → direct",
    description: "Загрузка/обновления Steam напрямую.",
    build: () =>
      template("Steam", "direct", {
        domainSuffixes: [
          "steampowered.com",
          "steamcontent.com",
          "steamcommunity.com",
          "steamserver.net",
          "cm.steampowered.com",
        ],
      }),
  },
  {
    key: "ads-block",
    label: "Реклама → block",
    description: "Базовый набор рекламных доменов — заблокировать.",
    build: () =>
      template("Реклама (block)", "block", {
        domainSuffixes: [
          "doubleclick.net",
          "googlesyndication.com",
          "googleadservices.com",
          "adservice.google.com",
          "adnxs.com",
        ],
      }),
  },
];
