-- Migration 111: IEEE/MSA Standards Wavelength Lookup
-- Ground-Truth für Wellenlänge basierend auf Standard-Spezifikation
-- Quelle: IEEE 802.3, SFF-8472, SFF-8436, SFF-8661, SFF-8679, MSA specs

CREATE TABLE IF NOT EXISTS ieee_wavelength_lookup (
  id              SERIAL PRIMARY KEY,
  form_factor     TEXT    NOT NULL,
  speed_gbps      NUMERIC NOT NULL,
  fiber_type      TEXT    NOT NULL,   -- 'SMF', 'MMF', 'DAC', 'AOC'
  reach_min_m     INTEGER NOT NULL,
  reach_max_m     INTEGER NOT NULL,
  wavelength_tx_nm INTEGER,           -- NULL for Copper/RJ45 (no optical wavelength)
  wavelength_rx_nm INTEGER,           -- NULL = gleich wie TX (kein BiDi)
  connector_type  TEXT    NOT NULL,
  ieee_standard   TEXT,               -- z.B. '802.3ae', 'SFF-8431'
  notes           TEXT,
  UNIQUE (form_factor, speed_gbps, fiber_type, reach_min_m, reach_max_m)
);

INSERT INTO ieee_wavelength_lookup
  (form_factor, speed_gbps, fiber_type, reach_min_m, reach_max_m, wavelength_tx_nm, wavelength_rx_nm, connector_type, ieee_standard, notes)
VALUES
-- ── SFP (1G) ─────────────────────────────────────────────────────────────────
  ('SFP',  1,   'MMF', 0,     550,   850,  NULL,  'LC', '802.3z',   '1000BASE-SX'),
  ('SFP',  1,   'SMF', 0,    10000,  1310, NULL,  'LC', '802.3z',   '1000BASE-LX'),
  ('SFP',  1,   'SMF', 0,    40000,  1310, NULL,  'LC', '802.3z',   '1000BASE-EX'),
  ('SFP',  1,   'SMF', 0,    70000,  1550, NULL,  'LC', '802.3z',   '1000BASE-ZX'),
  ('SFP',  1,   'SMF', 0,    10000,  1270, 1330,  'LC', 'SFF-8472', '1000BASE-BX10-U BiDi'),
  ('SFP',  1,   'SMF', 0,    10000,  1330, 1270,  'LC', 'SFF-8472', '1000BASE-BX10-D BiDi'),
  ('SFP',  1,   'Copper', 0,   100,  NULL, NULL,  'RJ45','802.3ab', '1000BASE-T'),
-- ── SFP+ (10G) ───────────────────────────────────────────────────────────────
  ('SFP+', 10,  'MMF', 0,     300,   850,  NULL,  'LC', '802.3ae',  '10GBASE-SR'),
  ('SFP+', 10,  'SMF', 0,   10000,  1310,  NULL,  'LC', '802.3ae',  '10GBASE-LR'),
  ('SFP+', 10,  'SMF', 0,   40000,  1310,  NULL,  'LC', '802.3ae',  '10GBASE-ER'),
  ('SFP+', 10,  'SMF', 0,   80000,  1550,  NULL,  'LC', '802.3ae',  '10GBASE-ZR'),
  ('SFP+', 10,  'SMF', 0,   10000,  1270,  1330,  'LC', 'SFF-8431', '10GBASE-BX10-U BiDi'),
  ('SFP+', 10,  'SMF', 0,   10000,  1330,  1270,  'LC', 'SFF-8431', '10GBASE-BX10-D BiDi'),
  ('SFP+', 10,  'SMF', 0,   20000,  1270,  1330,  'LC', 'SFF-8431', '10GBASE-BX20-U BiDi'),
  ('SFP+', 10,  'SMF', 0,   20000,  1330,  1270,  'LC', 'SFF-8431', '10GBASE-BX20-D BiDi'),
  ('SFP+', 10,  'DAC', 0,       7,  NULL,  NULL,  'SFP+','SFF-8431','10G DAC Twinax'),
  ('SFP+', 10,  'AOC', 0,     100,  850,   NULL,  'LC', 'SFF-8431', '10G AOC'),
-- ── SFP28 (25G) ──────────────────────────────────────────────────────────────
  ('SFP28', 25, 'MMF', 0,     100,   850,  NULL,  'LC', '802.3by',  '25GBASE-SR'),
  ('SFP28', 25, 'SMF', 0,   10000,  1310,  NULL,  'LC', '802.3cc',  '25GBASE-LR'),
  ('SFP28', 25, 'SMF', 0,    2000,  1310,  NULL,  'LC', '25GBASE-DR','25GBASE-DR'),
  ('SFP28', 25, 'SMF', 0,   10000,  1270,  1330,  'LC', '802.3cc',  '25GBASE-BX10-U BiDi'),
  ('SFP28', 25, 'SMF', 0,   10000,  1330,  1270,  'LC', '802.3cc',  '25GBASE-BX10-D BiDi'),
  ('SFP28', 25, 'DAC', 0,       5,  NULL,  NULL,  'SFP28','802.3by','25G DAC'),
-- ── QSFP+ (40G) ──────────────────────────────────────────────────────────────
  ('QSFP+', 40, 'MMF', 0,     150,   850,  NULL,  'MPO-12','802.3ba','40GBASE-SR4'),
  ('QSFP+', 40, 'SMF', 0,   10000,  1310,  NULL,  'LC', '802.3ba',  '40GBASE-LR4 CWDM4'),
  ('QSFP+', 40, 'SMF', 0,    2000,  1310,  NULL,  'MPO-12','802.3bm','40GBASE-PSM4'),
  ('QSFP+', 40, 'DAC', 0,       7,  NULL,  NULL,  'QSFP+','802.3ba','40G DAC'),
-- ── QSFP28 (100G) ────────────────────────────────────────────────────────────
  ('QSFP28', 100, 'MMF', 0,    100,  850,  NULL,  'MPO-12','802.3bm','100GBASE-SR4'),
  ('QSFP28', 100, 'SMF', 0,  10000, 1310,  NULL,  'LC', '802.3cd',  '100GBASE-LR4 CWDM4'),
  ('QSFP28', 100, 'SMF', 0,    500, 1310,  NULL,  'MPO-12','802.3bj','100GBASE-DR (PSM4)'),
  ('QSFP28', 100, 'SMF', 0,  40000, 1310,  NULL,  'LC', '802.3ba',  '100GBASE-ER4'),
  ('QSFP28', 100, 'SMF', 0,   2000, 1310,  NULL,  'LC', 'CWDM4-MSA','100G CWDM4 2km'),
  ('QSFP28', 100, 'DAC', 0,      5, NULL,  NULL,  'QSFP28','802.3bj','100G DAC'),
  ('QSFP28', 100, 'AOC', 0,    100,  850,  NULL,  'MPO-12','802.3bm','100G AOC SR4'),
-- ── QSFP56 (200G) ────────────────────────────────────────────────────────────
  ('QSFP56', 200, 'MMF', 0,    100,  850,  NULL,  'MPO-16','802.3cd','200GBASE-SR4'),
  ('QSFP56', 200, 'SMF', 0,   2000, 1310,  NULL,  'LC', '802.3cd',  '200GBASE-DR4'),
  ('QSFP56', 200, 'SMF', 0,  10000, 1310,  NULL,  'LC', '802.3cd',  '200GBASE-FR4'),
  ('QSFP56', 200, 'SMF', 0,  40000, 1310,  NULL,  'LC', '802.3cd',  '200GBASE-LR4'),
-- ── QSFP-DD (400G) ───────────────────────────────────────────────────────────
  ('QSFP-DD', 400, 'MMF', 0,   100,  850,  NULL,  'MPO-16','802.3bs','400GBASE-SR8'),
  ('QSFP-DD', 400, 'SMF', 0,   500, 1310,  NULL,  'MPO-12','802.3bs','400GBASE-DR4'),
  ('QSFP-DD', 400, 'SMF', 0,  2000, 1310,  NULL,  'LC', '802.3bs',  '400GBASE-FR4'),
  ('QSFP-DD', 400, 'SMF', 0, 10000, 1310,  NULL,  'LC', '802.3bs',  '400GBASE-LR4'),
  ('QSFP-DD', 400, 'SMF', 0, 10000, 1310,  NULL,  'MPO-12','800G MSA','400GBASE-PSM4'),
  ('QSFP-DD', 400, 'DAC', 0,     5, NULL,  NULL,  'QSFP-DD','802.3bs','400G DAC'),
-- ── OSFP / QSFP-DD800 (800G) ─────────────────────────────────────────────────
  ('OSFP',    800, 'MMF', 0,    100,  850,  NULL,  'MPO-16','802.3df','800GBASE-SR8'),
  ('OSFP',    800, 'SMF', 0,    500, 1310,  NULL,  'MPO-12','802.3df','800GBASE-DR8'),
  ('OSFP',    800, 'SMF', 0,   2000, 1310,  NULL,  'LC', '802.3df',  '800GBASE-FR4 2x400G'),
  ('OSFP',    800, 'SMF', 0,  10000, 1310,  NULL,  'LC', '802.3df',  '800GBASE-LR4'),
  ('QSFP-DD800', 800, 'MMF', 0, 100, 850,  NULL,  'MPO-16','802.3df','800GBASE-SR8'),
  ('QSFP-DD800', 800, 'SMF', 0, 500, 1310, NULL,  'MPO-12','802.3df','800GBASE-DR8')
ON CONFLICT DO NOTHING;

CREATE INDEX IF NOT EXISTS idx_ieee_lookup ON ieee_wavelength_lookup
  (form_factor, speed_gbps, fiber_type, reach_min_m, reach_max_m);
