-- name: GetTotalMontlyEventStat :many
SELECT DATE_TRUNC('month', start_time) AS month,
    COUNT(*) AS event_count
FROM events
    JOIN leagues ON leagues.id = events.league_id
WHERE (
        events.is_featured = sqlc.narg('is_event_featured')
        OR sqlc.narg('is_event_featured') IS NULL
    )
    AND (
        leagues.is_featured = sqlc.narg('is_league_featured')
        OR sqlc.narg('is_league_featured') IS NULL
    )
    AND (
        events.league_id = sqlc.narg('league_id')
        OR sqlc.narg('league_id') IS NULL
    )
GROUP BY month
ORDER BY month;