-- Migration 026: Goal Type Filters
-- Date: 2026-03-27
-- Purpose: Enable filtered counting/aggregation (e.g., count only strength training)

-- Add filter_conditions column for flexible filtering
ALTER TABLE goal_type_definitions
ADD COLUMN IF NOT EXISTS filter_conditions JSONB;

COMMENT ON COLUMN goal_type_definitions.filter_conditions IS
'Optional filter conditions as JSON. Example: {"training_type": "strength"} to count only strength training sessions.
Supports any column in the source table. Format: {"column_name": "value"} or {"column_name": ["value1", "value2"]} for IN clause.';

-- Example usage (commented out):
/*
-- Count only strength training sessions per week
INSERT INTO goal_type_definitions (
    type_key, label_de, unit, icon, category,
    source_table, source_column, aggregation_method,
    filter_conditions,
    description, is_system
) VALUES (
    'strength_frequency', 'Krafttraining Häufigkeit', 'x/Woche', '🏋️', 'activity',
    'activity_log', 'id', 'count_7d',
    '{"training_type": "strength"}',
    'Anzahl Krafttraining-Einheiten pro Woche', false
) ON CONFLICT (type_key) DO NOTHING;

-- Count only cardio sessions per week
INSERT INTO goal_type_definitions (
    type_key, label_de, unit, icon, category,
    source_table, source_column, aggregation_method,
    filter_conditions,
    description, is_system
) VALUES (
    'cardio_frequency', 'Cardio Häufigkeit', 'x/Woche', '🏃', 'activity',
    'activity_log', 'id', 'count_7d',
    '{"training_type": "cardio"}',
    'Anzahl Cardio-Einheiten pro Woche', false
) ON CONFLICT (type_key) DO NOTHING;
*/
