-- name: GetTotalBetsMadeInRange :one
SELECT COUNT(*) AS total_bets
FROM bets
WHERE created_at BETWEEN sqlc.arg('from') AND sqlc.arg('to')
  AND (
    company_id = sqlc.narg('company_id')
    OR sqlc.narg('company_id') IS NULL
);
-- name: GetTotalCashMadeInRange :one
SELECT COALESCE(SUM(amount), 0) AS total_cash_made
FROM bets
WHERE created_at BETWEEN sqlc.arg('from') AND sqlc.arg('to')
  AND (
    company_id = sqlc.narg('company_id')
    OR sqlc.narg('company_id') IS NULL
);
-- name: GetTotalCashOutInRange :one
SELECT COALESCE(SUM(amount), 0) AS total_cash_out
FROM bets
WHERE created_at BETWEEN sqlc.arg('from') AND sqlc.arg('to')
  AND cashed_out = true
  AND (
    company_id = sqlc.narg('company_id')
    OR sqlc.narg('company_id') IS NULL
);
-- name: GetTotalCashBacksInRange :one
SELECT COALESCE(SUM(amount), 0) AS total_cash_backs
FROM bets
WHERE created_at BETWEEN sqlc.arg('from') AND sqlc.arg('to')
  AND status = 5
  AND (
    company_id = sqlc.narg('company_id')
    OR sqlc.narg('company_id') IS NULL
);
