/**
 * Migration 031 — Cisco 8000 Series Accuracy Update
 *
 * Fixes:
 * - 8201-32FH: corrected ASIC Q100→Q200, added full description, features, use_cases, flexbox_notes
 * - 8608: updated to modular system_type, improved description
 * - NEW: 8812 (12-slot chassis), 8818 (18-slot chassis), 8800-LC-36FH, 8800-LC-48H line cards
 *
 * Key facts added per research:
 * - Silicon One Q200 (7nm + HBM), NOT Q100
 * - DCO license required per 100G for ZR/ZR+ coherent optics (all vendors)
 * - No separate RTU license for grey (non-coherent) 3rd-party optics
 * - IOS XR PID check: "transceiver permit pid all" per-interface override
 * - Flexoptix FlexBox "Cisco Systems" mode = native OEM PID, no override needed
 * - QSFP28/QSFP+ backward-compatible in QSFP-DD cages; SFP/SFP28 need breakout cable
 * - QSA adapters NOT supported on QSFP-DD ports
 * - DOM readings may be incorrect with non-Cisco modules
 * - IOS XR upgrades can break previously working 3rd-party optics
 */

-- ============================================================
-- UPDATE 8201-32FH (fixed)
-- ============================================================
UPDATE switches SET
  description = '32-port 400GbE Service Provider router powered by Silicon One Q200 ASIC (7nm + HBM). All 32 QSFP-DD ports support 400G grey Ethernet and coherent QSFP-DD ZR/ZR+ / OpenZR+ optics (DCO license required per 100G for coherent mode). QSFP28 and QSFP+ are physically backward-compatible in QSFP-DD cages. SFP and SFP28 require breakout cables — QSA adapters NOT supported. IOS XR validates transceiver EEPROM/PID at insertion; unrecognized modules have TX laser disabled. No special license required for standard grey optics.',
  features = '["Silicon One Q200 (7nm+HBM)", "SRv6", "Segment Routing MPLS", "FlexAlgo", "Coherent ZR/ZR+ (all 32 ports)", "OpenZR+", "QSFP-DD backward compat QSFP28/QSFP+", "MACsec-256", "EVPN", "BGP-LU", "Telemetry gNMI/gRPC", "IOS XR"]'::jsonb,
  use_cases = ARRAY['Provider Edge', 'Internet Core', 'Peering Router', 'DCI / Cloud Backbone', '5G Transport', 'Routed Optical Networking (RON)'],
  flexbox_compat_mode = 'Cisco',
  flexbox_notes = 'IOS XR validates EEPROM/PID at insertion — unrecognized modules have TX laser disabled immediately. Per-interface override: "transceiver permit pid all" (NOT global; different from IOS "service unsupported-transceiver"). Warning: no TAC support; generates PFM alarm; may fail after IOS XR upgrades/SMUs due to driver changes; some modules never come up regardless of override. DCO License required for ZR/ZR+ coherent optics (billed per 100G — applies to all vendors including Cisco). Grey optics (QSFP28 SR4/LR4, 400G DR4 etc.) need no special license. Flexoptix FlexBox "Cisco Systems" mode writes Cisco OEM PID into transceiver EEPROM — IOS XR accepts it natively without any override command. DOM readings may show incorrect values with non-Cisco modules (not traffic-affecting but impacts monitoring).',
  category = 'SP',
  lifecycle_status = 'Active',
  system_type = 'fixed',
  is_linecard = false,
  max_speed_gbps = 400,
  switching_capacity_tbps = 12.8,
  total_ports = 32,
  ports_config = '{"400G_QSFP-DD": 32}'::jsonb
WHERE model = '8201-32FH';

-- ============================================================
-- UPDATE 8608 (modular chassis)
-- ============================================================
UPDATE switches SET
  description = 'Cisco 8608 — 8-slot modular chassis router for Tier-1 SP core and DCI. Accepts 8800-series line cards (48×100G QSFP28, 36×400G QSFP-DD, etc.). Powered by Silicon One Q200 ASICs per line card. IOS XR validates transceiver EEPROM/PID per line card at insertion.',
  system_type = 'modular',
  is_linecard = false,
  chassis_model = NULL,
  features = '["8 line card slots", "Silicon One Q200 per LC", "SRv6", "Segment Routing", "Coherent ZR/ZR+", "EVPN", "BGP-LU", "Telemetry", "IOS XR"]'::jsonb,
  use_cases = ARRAY['Tier-1 SP Core', 'Provider Edge', 'DCI', 'Peering', 'Multi-service Backbone'],
  flexbox_compat_mode = 'Cisco',
  flexbox_notes = 'IOS XR validates EEPROM/PID at insertion — unrecognized modules have TX laser disabled immediately. Per-interface override: "transceiver permit pid all" (NOT global; different from IOS "service unsupported-transceiver"). Warning: no TAC support; generates PFM alarm; may fail after IOS XR upgrades/SMUs due to driver changes; some modules never come up regardless of override. DCO License required for ZR/ZR+ coherent optics (billed per 100G — applies to all vendors including Cisco). Grey optics (QSFP28 SR4/LR4, 400G DR4 etc.) need no special license. Flexoptix FlexBox "Cisco Systems" mode writes Cisco OEM PID into transceiver EEPROM — IOS XR accepts it natively without any override command. DOM readings may show incorrect values with non-Cisco modules (not traffic-affecting but impacts monitoring).',
  category = 'SP',
  lifecycle_status = 'Active'
WHERE model = '8608';

-- ============================================================
-- INSERT 8812 modular chassis
-- ============================================================
INSERT INTO switches (
  id, vendor_id, model, series, category, description, max_speed_gbps,
  switching_capacity_tbps, total_ports, ports_config, system_type, is_linecard,
  flexbox_compat_mode, flexbox_notes, lifecycle_status, features, use_cases
)
SELECT
  gen_random_uuid(),
  v.id,
  '8812',
  'Cisco 8000',
  'SP',
  'Cisco 8812 — 12-slot modular chassis for ultra-high-capacity Tier-1 SP core. Accepts 8800-series line cards (36×400G QSFP-DD or 48×100G QSFP28 per slot). Silicon One Q200 ASICs per LC. IOS XR validates EEPROM/PID per line card. Coherent ZR/ZR+ on compatible LCs (DCO license per 100G required).',
  400,
  57.6,
  432,
  '{"slots": 12, "max_per_slot_400G_QSFP-DD": 36, "max_per_slot_100G_QSFP28": 48}'::jsonb,
  'modular',
  false,
  'Cisco',
  'IOS XR validates EEPROM/PID at insertion — unrecognized modules have TX laser disabled immediately. Per-interface override: "transceiver permit pid all" (NOT global; different from IOS "service unsupported-transceiver"). Warning: no TAC support; generates PFM alarm; may fail after IOS XR upgrades/SMUs due to driver changes; some modules never come up regardless of override. DCO License required for ZR/ZR+ coherent optics (billed per 100G — applies to all vendors including Cisco). Grey optics (QSFP28 SR4/LR4, 400G DR4 etc.) need no special license. Flexoptix FlexBox "Cisco Systems" mode writes Cisco OEM PID into transceiver EEPROM — IOS XR accepts it natively without any override command. DOM readings may show incorrect values with non-Cisco modules (not traffic-affecting but impacts monitoring).',
  'Active',
  '["12 slots", "Silicon One Q200 per LC", "SRv6", "Segment Routing", "Coherent ZR/ZR+", "OpenZR+", "EVPN", "BGP-LU", "Telemetry gNMI", "MACsec-256", "IOS XR"]'::jsonb,
  ARRAY['Tier-1 SP Core', 'Multi-Terabit Backbone', 'DCI', 'Peering', 'Internet Exchange Core']
FROM vendors v WHERE v.name = 'Cisco'
AND NOT EXISTS (SELECT 1 FROM switches WHERE model = '8812');

-- ============================================================
-- INSERT 8818 modular chassis
-- ============================================================
INSERT INTO switches (
  id, vendor_id, model, series, category, description, max_speed_gbps,
  switching_capacity_tbps, total_ports, ports_config, system_type, is_linecard,
  flexbox_compat_mode, flexbox_notes, lifecycle_status, features, use_cases
)
SELECT
  gen_random_uuid(),
  v.id,
  '8818',
  'Cisco 8000',
  'SP',
  'Cisco 8818 — 18-slot modular chassis, largest in the Cisco 8000 family. Designed for hyperscale SP core networks. Accepts 8800-series line cards (36×400G QSFP-DD or 48×100G QSFP28 per slot). Silicon One Q200 ASICs per LC. Up to 18 × 36 = 648 ports of 400G.',
  400,
  86.4,
  648,
  '{"slots": 18, "max_per_slot_400G_QSFP-DD": 36, "max_per_slot_100G_QSFP28": 48}'::jsonb,
  'modular',
  false,
  'Cisco',
  'IOS XR validates EEPROM/PID at insertion — unrecognized modules have TX laser disabled immediately. Per-interface override: "transceiver permit pid all" (NOT global; different from IOS "service unsupported-transceiver"). Warning: no TAC support; generates PFM alarm; may fail after IOS XR upgrades/SMUs due to driver changes; some modules never come up regardless of override. DCO License required for ZR/ZR+ coherent optics (billed per 100G — applies to all vendors including Cisco). Grey optics (QSFP28 SR4/LR4, 400G DR4 etc.) need no special license. Flexoptix FlexBox "Cisco Systems" mode writes Cisco OEM PID into transceiver EEPROM — IOS XR accepts it natively without any override command. DOM readings may show incorrect values with non-Cisco modules (not traffic-affecting but impacts monitoring).',
  'Active',
  '["18 slots", "Silicon One Q200 per LC", "SRv6", "Segment Routing", "Coherent ZR/ZR+", "OpenZR+", "EVPN", "BGP-LU", "Telemetry gNMI", "MACsec-256", "IOS XR", "Hyperscale"]'::jsonb,
  ARRAY['Tier-1 SP Core', 'Hyperscale Backbone', 'Multi-Terabit Peering', 'DCI', 'Internet Exchange Core']
FROM vendors v WHERE v.name = 'Cisco'
AND NOT EXISTS (SELECT 1 FROM switches WHERE model = '8818');

-- ============================================================
-- INSERT 8800-LC-36FH (400G QSFP-DD line card)
-- ============================================================
INSERT INTO switches (
  id, vendor_id, model, series, category, description, max_speed_gbps,
  total_ports, ports_config, system_type, is_linecard,
  chassis_model, slot_type, flexbox_compat_mode, flexbox_notes, lifecycle_status,
  features, use_cases
)
SELECT
  gen_random_uuid(),
  v.id,
  '8800-LC-36FH',
  'Cisco 8000',
  'SP',
  'Cisco 8800-LC-36FH — 36-port 400GbE line card for 8800-series modular chassis (8608, 8812, 8818). Silicon One Q200 ASIC. 36 × QSFP-DD ports supporting 400G Ethernet and coherent QSFP-DD ZR/ZR+ optics. QSFP28/QSFP+ physically backward-compatible in QSFP-DD cages. SFP/SFP28 require breakout cables — QSA adapters NOT supported.',
  400,
  36,
  '{"400G_QSFP-DD": 36}'::jsonb,
  'fixed',
  true,
  'Cisco 8000',
  'Cisco 8800 LC Slot',
  'Cisco',
  'IOS XR validates EEPROM/PID at insertion — unrecognized modules have TX laser disabled immediately. Per-interface override: "transceiver permit pid all" (NOT global; different from IOS "service unsupported-transceiver"). Warning: no TAC support; generates PFM alarm; may fail after IOS XR upgrades/SMUs due to driver changes; some modules never come up regardless of override. DCO License required for ZR/ZR+ coherent optics (billed per 100G — applies to all vendors including Cisco). Grey optics (QSFP28 SR4/LR4, 400G DR4 etc.) need no special license. Flexoptix FlexBox "Cisco Systems" mode writes Cisco OEM PID into transceiver EEPROM — IOS XR accepts it natively without any override command. DOM readings may show incorrect values with non-Cisco modules (not traffic-affecting but impacts monitoring).',
  'Active',
  '["Silicon One Q200", "36×400G QSFP-DD", "Coherent ZR/ZR+", "OpenZR+", "QSFP28/QSFP+ backward compat", "SRv6", "Segment Routing", "MACsec-256", "IOS XR"]'::jsonb,
  ARRAY['SP Core Line Card', '400G Dense', 'Coherent DCI', 'Routed Optical Networking']
FROM vendors v WHERE v.name = 'Cisco'
AND NOT EXISTS (SELECT 1 FROM switches WHERE model = '8800-LC-36FH');

-- ============================================================
-- INSERT 8800-LC-48H (100G QSFP28 line card)
-- ============================================================
INSERT INTO switches (
  id, vendor_id, model, series, category, description, max_speed_gbps,
  total_ports, ports_config, system_type, is_linecard,
  chassis_model, slot_type, flexbox_compat_mode, flexbox_notes, lifecycle_status,
  features, use_cases
)
SELECT
  gen_random_uuid(),
  v.id,
  '8800-LC-48H',
  'Cisco 8000',
  'SP',
  'Cisco 8800-LC-48H — 48-port 100GbE line card for 8800-series modular chassis (8608, 8812, 8818). Silicon One Q200L ASIC. 48 × QSFP28 ports. Supports QSFP+ (40G) backward-compatible. SFP/SFP28 require breakout cables. No QSA adapter support.',
  100,
  48,
  '{"100G_QSFP28": 48}'::jsonb,
  'fixed',
  true,
  'Cisco 8000',
  'Cisco 8800 LC Slot',
  'Cisco',
  'IOS XR validates EEPROM/PID at insertion — unrecognized modules have TX laser disabled immediately. Per-interface override: "transceiver permit pid all" (NOT global; different from IOS "service unsupported-transceiver"). Warning: no TAC support; generates PFM alarm; may fail after IOS XR upgrades/SMUs due to driver changes; some modules never come up regardless of override. DCO License required for ZR/ZR+ coherent optics (billed per 100G — applies to all vendors including Cisco). Grey optics (QSFP28 SR4/LR4, 400G DR4 etc.) need no special license. Flexoptix FlexBox "Cisco Systems" mode writes Cisco OEM PID into transceiver EEPROM — IOS XR accepts it natively without any override command. DOM readings may show incorrect values with non-Cisco modules (not traffic-affecting but impacts monitoring).',
  'Active',
  '["Silicon One Q200L", "48×100G QSFP28", "QSFP+ backward compat", "Breakout 4×25G", "SRv6", "Segment Routing", "IOS XR"]'::jsonb,
  ARRAY['SP Core Line Card', '100G Aggregation', 'High-density 100G']
FROM vendors v WHERE v.name = 'Cisco'
AND NOT EXISTS (SELECT 1 FROM switches WHERE model = '8800-LC-48H');

-- Update search_vector for all Cisco 8000 models
UPDATE switches SET search_vector =
  to_tsvector('english',
    COALESCE(model, '') || ' ' ||
    COALESCE(series, '') || ' ' ||
    COALESCE(description, '') || ' ' ||
    COALESCE(category, '')
  )
WHERE series = 'Cisco 8000';
