-- Migration: Add Time Clock Aggregation Sync Hook
-- Date: 2025-10-08
-- Description: Creates sync hook for automatic time clock aggregation with org_id support

-- Insert time clock aggregation hook
-- This hook automatically calculates time clock aggregates when time_clock_aggregates are requested
INSERT INTO sync_hooks (name, description, trigger_table, trigger_operations, hook_type, priority, config, is_active)
VALUES (
    'time_clock_aggregation',
    'Auto-aggregate time_clocks data into time_clock_aggregates by user and org',
    'time_clock_aggregates',
    ARRAY['PULL'],
    'custom',
    100,
    '{
        "endpoint": "/api/timeclock/aggregates",
        "require_date_filter": true
    }'::jsonb,
    true
)
ON CONFLICT (name) DO UPDATE
SET 
    hook_type = 'custom',
    config = '{
        "endpoint": "/api/timeclock/aggregates",
        "require_date_filter": true
    }'::jsonb,
    description = EXCLUDED.description,
    updated_at = NOW();

COMMENT ON TABLE sync_hooks IS 'Declarative sync hooks - time_clock_aggregation groups by user_id AND org_id for multi-tenant support';
