-- dev_seed.sql (PostgreSQL) — development test data
--
-- Running this script is idempotent: existing rows are left untouched
-- and missing rows are inserted.  Safe to run multiple times.
--
-- Load with: cargo run --features ssr --bin seed

-- ── Networks ──────────────────────────────────────────────────────────────────

INSERT INTO networks (cidr) VALUES
    ('192.168.1.0/24'),
    ('192.168.10.0/24'),
    ('10.0.0.0/8'),
    ('172.16.0.0/16')
ON CONFLICT (cidr) DO NOTHING;

-- ── Hosts ─────────────────────────────────────────────────────────────────────
-- Hosts have no UNIQUE constraint, so we guard with WHERE NOT EXISTS.

-- LAN — 192.168.1.0/24
INSERT INTO hosts (name, ip, network_id)
SELECT name, ip, (SELECT id FROM networks WHERE cidr = '192.168.1.0/24')
FROM (VALUES
    ('gateway',        '192.168.1.1'),
    ('workstation-01', '192.168.1.10'),
    ('workstation-02', '192.168.1.11'),
    ('workstation-03', '192.168.1.12'),
    ('nas-01',         '192.168.1.20'),
    ('printer-01',     '192.168.1.50')
) AS t(name, ip)
WHERE NOT EXISTS (SELECT 1 FROM hosts WHERE hosts.name = t.name AND hosts.ip = t.ip);

-- DMZ — 192.168.10.0/24
INSERT INTO hosts (name, ip, network_id)
SELECT name, ip, (SELECT id FROM networks WHERE cidr = '192.168.10.0/24')
FROM (VALUES
    ('web-server-01',  '192.168.10.10'),
    ('web-server-02',  '192.168.10.11'),
    ('db-server-01',   '192.168.10.20'),
    ('mail-server-01', '192.168.10.30')
) AS t(name, ip)
WHERE NOT EXISTS (SELECT 1 FROM hosts WHERE hosts.name = t.name AND hosts.ip = t.ip);

-- Corporate backbone — 10.0.0.0/8
INSERT INTO hosts (name, ip, network_id)
SELECT name, ip, (SELECT id FROM networks WHERE cidr = '10.0.0.0/8')
FROM (VALUES
    ('core-switch-01',   '10.0.0.1'),
    ('monitoring-01',    '10.0.1.10'),
    ('backup-server-01', '10.0.1.20'),
    ('log-server-01',    '10.0.1.30')
) AS t(name, ip)
WHERE NOT EXISTS (SELECT 1 FROM hosts WHERE hosts.name = t.name AND hosts.ip = t.ip);

-- VPN — 172.16.0.0/16
INSERT INTO hosts (name, ip, network_id)
SELECT name, ip, (SELECT id FROM networks WHERE cidr = '172.16.0.0/16')
FROM (VALUES
    ('vpn-gateway-01', '172.16.0.1'),
    ('vpn-client-01',  '172.16.1.10'),
    ('vpn-client-02',  '172.16.1.11')
) AS t(name, ip)
WHERE NOT EXISTS (SELECT 1 FROM hosts WHERE hosts.name = t.name AND hosts.ip = t.ip);
