// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.29.0
// source: virtual_games.sql

package dbgen

import (
	"context"

	"github.com/jackc/pgx/v5/pgtype"
)

const CreateVirtualGameSession = `-- name: CreateVirtualGameSession :one
INSERT INTO virtual_game_sessions (
    user_id, game_id, session_token, currency, status, expires_at
) VALUES (
    $1, $2, $3, $4, $5, $6
) RETURNING id, user_id, game_id, session_token, currency, status, created_at, updated_at, expires_at
`

type CreateVirtualGameSessionParams struct {
	UserID       int64              `json:"user_id"`
	GameID       string             `json:"game_id"`
	SessionToken string             `json:"session_token"`
	Currency     string             `json:"currency"`
	Status       string             `json:"status"`
	ExpiresAt    pgtype.Timestamptz `json:"expires_at"`
}

func (q *Queries) CreateVirtualGameSession(ctx context.Context, arg CreateVirtualGameSessionParams) (VirtualGameSession, error) {
	row := q.db.QueryRow(ctx, CreateVirtualGameSession,
		arg.UserID,
		arg.GameID,
		arg.SessionToken,
		arg.Currency,
		arg.Status,
		arg.ExpiresAt,
	)
	var i VirtualGameSession
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.GameID,
		&i.SessionToken,
		&i.Currency,
		&i.Status,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.ExpiresAt,
	)
	return i, err
}

const CreateVirtualGameTransaction = `-- name: CreateVirtualGameTransaction :one
INSERT INTO virtual_game_transactions (
    session_id, user_id, wallet_id, transaction_type, amount, currency, external_transaction_id, status
) VALUES (
    $1, $2, $3, $4, $5, $6, $7, $8
) RETURNING id, session_id, user_id, wallet_id, transaction_type, amount, currency, external_transaction_id, status, created_at, updated_at
`

type CreateVirtualGameTransactionParams struct {
	SessionID             int64  `json:"session_id"`
	UserID                int64  `json:"user_id"`
	WalletID              int64  `json:"wallet_id"`
	TransactionType       string `json:"transaction_type"`
	Amount                int64  `json:"amount"`
	Currency              string `json:"currency"`
	ExternalTransactionID string `json:"external_transaction_id"`
	Status                string `json:"status"`
}

func (q *Queries) CreateVirtualGameTransaction(ctx context.Context, arg CreateVirtualGameTransactionParams) (VirtualGameTransaction, error) {
	row := q.db.QueryRow(ctx, CreateVirtualGameTransaction,
		arg.SessionID,
		arg.UserID,
		arg.WalletID,
		arg.TransactionType,
		arg.Amount,
		arg.Currency,
		arg.ExternalTransactionID,
		arg.Status,
	)
	var i VirtualGameTransaction
	err := row.Scan(
		&i.ID,
		&i.SessionID,
		&i.UserID,
		&i.WalletID,
		&i.TransactionType,
		&i.Amount,
		&i.Currency,
		&i.ExternalTransactionID,
		&i.Status,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const GetVirtualGameSessionByToken = `-- name: GetVirtualGameSessionByToken :one
SELECT id, user_id, game_id, session_token, currency, status, created_at, updated_at, expires_at
FROM virtual_game_sessions
WHERE session_token = $1
`

func (q *Queries) GetVirtualGameSessionByToken(ctx context.Context, sessionToken string) (VirtualGameSession, error) {
	row := q.db.QueryRow(ctx, GetVirtualGameSessionByToken, sessionToken)
	var i VirtualGameSession
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.GameID,
		&i.SessionToken,
		&i.Currency,
		&i.Status,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.ExpiresAt,
	)
	return i, err
}

const GetVirtualGameTransactionByExternalID = `-- name: GetVirtualGameTransactionByExternalID :one
SELECT id, session_id, user_id, wallet_id, transaction_type, amount, currency, external_transaction_id, status, created_at, updated_at
FROM virtual_game_transactions
WHERE external_transaction_id = $1
`

func (q *Queries) GetVirtualGameTransactionByExternalID(ctx context.Context, externalTransactionID string) (VirtualGameTransaction, error) {
	row := q.db.QueryRow(ctx, GetVirtualGameTransactionByExternalID, externalTransactionID)
	var i VirtualGameTransaction
	err := row.Scan(
		&i.ID,
		&i.SessionID,
		&i.UserID,
		&i.WalletID,
		&i.TransactionType,
		&i.Amount,
		&i.Currency,
		&i.ExternalTransactionID,
		&i.Status,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const UpdateVirtualGameSessionStatus = `-- name: UpdateVirtualGameSessionStatus :exec
UPDATE virtual_game_sessions
SET status = $2, updated_at = CURRENT_TIMESTAMP
WHERE id = $1
`

type UpdateVirtualGameSessionStatusParams struct {
	ID     int64  `json:"id"`
	Status string `json:"status"`
}

func (q *Queries) UpdateVirtualGameSessionStatus(ctx context.Context, arg UpdateVirtualGameSessionStatusParams) error {
	_, err := q.db.Exec(ctx, UpdateVirtualGameSessionStatus, arg.ID, arg.Status)
	return err
}

const UpdateVirtualGameTransactionStatus = `-- name: UpdateVirtualGameTransactionStatus :exec
UPDATE virtual_game_transactions
SET status = $2, updated_at = CURRENT_TIMESTAMP
WHERE id = $1
`

type UpdateVirtualGameTransactionStatusParams struct {
	ID     int64  `json:"id"`
	Status string `json:"status"`
}

func (q *Queries) UpdateVirtualGameTransactionStatus(ctx context.Context, arg UpdateVirtualGameTransactionStatusParams) error {
	_, err := q.db.Exec(ctx, UpdateVirtualGameTransactionStatus, arg.ID, arg.Status)
	return err
}
