-- name: CreateBet :one
INSERT INTO bets (
        amount,
        total_odds,
        status,
        full_name,
        phone_number,
        branch_id,
        user_id,
        is_shop_bet,
        cashout_id,
        company_id
    )
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
RETURNING *;
-- name: CreateBetOutcome :copyfrom
INSERT INTO bet_outcomes (
        bet_id,
        sport_id,
        event_id,
        odd_id,
        home_team_name,
        away_team_name,
        market_id,
        market_name,
        odd,
        odd_name,
        odd_header,
        odd_handicap,
        expires
    )
VALUES (
        $1,
        $2,
        $3,
        $4,
        $5,
        $6,
        $7,
        $8,
        $9,
        $10,
        $11,
        $12,
        $13
    );
-- name: GetAllBets :many
SELECT *
FROM bet_with_outcomes
wHERE (
        branch_id = $1
        OR $1 IS NULL
    )
    AND (
        company_id = $2
        OR $2 IS NULL
    )
    AND (
        user_id = $3
        OR $3 IS NULL
    );
-- name: GetBetByID :one
SELECT *
FROM bet_with_outcomes
WHERE id = $1;
-- name: GetBetByCashoutID :one
SELECT *
FROM bet_with_outcomes
WHERE cashout_id = $1;
-- name: GetBetByBranchID :many
SELECT *
FROM bet_with_outcomes
WHERE branch_id = $1;
-- name: GetBetByUserID :many
SELECT *
FROM bet_with_outcomes
WHERE user_id = $1;
-- name: GetBetOutcomeByEventID :many
SELECT *
FROM bet_outcomes
WHERE event_id = $1;
-- name: GetBetOutcomeByBetID :many
SELECT *
FROM bet_outcomes
WHERE bet_id = $1;
-- name: UpdateCashOut :exec
UPDATE bets
SET cashed_out = $2,
    updated_at = CURRENT_TIMESTAMP
WHERE id = $1;
-- name: UpdateBetOutcomeStatus :one
UPDATE bet_outcomes
SET status = $1
WHERE id = $2
RETURNING *;
-- name: UpdateStatus :exec
UPDATE bets
SET status = $1,
    updated_at = CURRENT_TIMESTAMP
WHERE id = $2;
-- name: DeleteBet :exec
DELETE FROM bets
WHERE id = $1;
-- name: DeleteBetOutcome :exec
DELETE FROM bet_outcomes
WHERE bet_id = $1;