-- VPS 厂商池
CREATE TABLE providers (
  id          INTEGER PRIMARY KEY AUTOINCREMENT,
  name        TEXT NOT NULL,
  api_kind    TEXT NOT NULL,
  regions     TEXT NOT NULL,                       -- JSON
  pool        TEXT NOT NULL CHECK (pool IN ('consumable','premium')),
  enabled     INTEGER NOT NULL DEFAULT 1,
  note        TEXT NULL
);

-- 节点。status CHECK 预置最终全集（含 blocked_*，使 000010 在 SQLite 成为 no-op）。
CREATE TABLE nodes (
  id           INTEGER PRIMARY KEY AUTOINCREMENT,
  uuid         TEXT NOT NULL UNIQUE,
  region       TEXT NOT NULL,
  name_zh      TEXT NOT NULL,
  name_en      TEXT NOT NULL,
  role         TEXT NOT NULL DEFAULT 'entry' CHECK (role IN ('entry','relay','exit')),
  tier         TEXT NOT NULL CHECK (tier IN ('free','pro')),
  endpoint     TEXT NOT NULL,
  hy2_port     INTEGER NULL,
  reality_pbk  TEXT NOT NULL,
  reality_sni  TEXT NOT NULL,
  provider_id  INTEGER NOT NULL,
  tags         TEXT NULL,                          -- JSON
  status       TEXT NOT NULL DEFAULT 'provisioning'
               CHECK (status IN ('provisioning','probing','up','draining','down','destroyed','blocked_suspect','blocked_confirmed')),
  weight       INTEGER NOT NULL DEFAULT 100,
  created_at   DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (provider_id) REFERENCES providers(id)
);
CREATE INDEX idx_nodes_status_tier ON nodes (status, tier);
