-- IT0 Pool Servers (public schema)
-- Platform-level server pool for OpenClaw instance deployment
-- Managed by platform_admin only

CREATE TABLE IF NOT EXISTS public.pool_servers (
    id                  UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    name                VARCHAR(100) NOT NULL,               -- Display name, e.g. "训练服务器"
    host                VARCHAR(255) NOT NULL,               -- IP or hostname
    ssh_port            INT NOT NULL DEFAULT 22,
    ssh_user            VARCHAR(100) NOT NULL,
    ssh_key_encrypted   TEXT NOT NULL,                       -- AES-256 encrypted private key (base64)
    ssh_key_iv          TEXT NOT NULL,                       -- AES-256 IV (base64)
    max_instances       INT NOT NULL DEFAULT 10,             -- Admin-set capacity limit
    current_instances   INT NOT NULL DEFAULT 0,              -- Live counter, updated on deploy/remove
    status              VARCHAR(20) NOT NULL DEFAULT 'active', -- active | maintenance | offline
    region              VARCHAR(100),                        -- Optional label e.g. "香港", "深圳"
    notes               TEXT,
    created_at          TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at          TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_pool_servers_status ON public.pool_servers(status);
