-- name: GetLeagueEventStat :many
SELECT leagues.id,
    leagues.name,
    COUNT(*) AS total_events,
    COUNT(*) FILTER (
        WHERE events.status = 'upcoming'
    ) AS pending,
    COUNT(*) FILTER (
        WHERE events.status = 'in_play'
    ) AS in_play,
    COUNT(*) FILTER (
        WHERE events.status = 'to_be_fixed'
    ) AS to_be_fixed,
    COUNT(*) FILTER (
        WHERE events.status = 'ended'
    ) AS ended,
    COUNT(*) FILTER (
        WHERE events.status = 'postponed'
    ) AS postponed,
    COUNT(*) FILTER (
        WHERE events.status = 'cancelled'
    ) AS cancelled,
    COUNT(*) FILTER (
        WHERE events.status = 'walkover'
    ) AS walkover,
    COUNT(*) FILTER (
        WHERE events.status = 'interrupted'
    ) AS interrupted,
    COUNT(*) FILTER (
        WHERE events.status = 'abandoned'
    ) AS abandoned,
    COUNT(*) FILTER (
        WHERE events.status = 'retired'
    ) AS retired,
    COUNT(*) FILTER (
        WHERE events.status = 'suspended'
    ) AS suspended,
    COUNT(*) FILTER (
        WHERE events.status = 'decided_by_fa'
    ) AS decided_by_fa,
    COUNT(*) FILTER (
        WHERE events.status = 'removed'
    ) AS removed
FROM leagues
    JOIN events ON leagues.id = events.league_id
GROUP BY leagues.id,
    leagues.name;