-- Fix missing features for v9c feature enforcement
-- 2026-03-20

-- Add missing features
INSERT INTO features (id, name, description, category, limit_type, reset_period, default_limit, active) VALUES
    ('data_export', 'Daten exportieren', 'CSV/JSON/ZIP Export', 'export', 'count', 'monthly', 0, true),
    ('csv_import', 'CSV importieren', 'FDDB/Apple Health CSV Import + ZIP Backup Import', 'import', 'count', 'monthly', 0, true)
ON CONFLICT (id) DO NOTHING;

-- Add tier limits for new features
-- FREE tier
INSERT INTO tier_limits (tier_id, feature_id, limit_value) VALUES
    ('free', 'data_export', 0),   -- Kein Export
    ('free', 'csv_import', 0)     -- Kein Import
ON CONFLICT (tier_id, feature_id) DO NOTHING;

-- BASIC tier
INSERT INTO tier_limits (tier_id, feature_id, limit_value) VALUES
    ('basic', 'data_export', 5),  -- 5 Exporte/Monat
    ('basic', 'csv_import', 3)    -- 3 Imports/Monat
ON CONFLICT (tier_id, feature_id) DO NOTHING;

-- PREMIUM tier
INSERT INTO tier_limits (tier_id, feature_id, limit_value) VALUES
    ('premium', 'data_export', NULL),  -- Unbegrenzt
    ('premium', 'csv_import', NULL)    -- Unbegrenzt
ON CONFLICT (tier_id, feature_id) DO NOTHING;

-- SELFHOSTED tier
INSERT INTO tier_limits (tier_id, feature_id, limit_value) VALUES
    ('selfhosted', 'data_export', NULL),  -- Unbegrenzt
    ('selfhosted', 'csv_import', NULL)    -- Unbegrenzt
ON CONFLICT (tier_id, feature_id) DO NOTHING;
